##Install Packages if Needed
if (!require("ggplot2")) install.packages("ggplot2")
if (!require("vegan")) install.packages("vegan")
Loading required package: vegan
Loading required package: permute
Loading required package: lattice
This is vegan 2.6-4
if (!require("FactoMineR")) install.packages("FactoMineR")
Loading required package: FactoMineR
Warning: package ‘FactoMineR’ was built under R version 4.3.2Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
if (!require("factoextra")) install.packages("factoextra")
Loading required package: factoextra
Warning: package ‘factoextra’ was built under R version 4.3.2Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
##Load Packages
library("ggplot2")
library("vegan")
library("FactoMineR")
library("factoextra")
Note: Run “Graphing Parameters” section from 01_ExperimentalSetup.R file
##Load Data
Color<-read.csv("Data/Color.csv", header=TRUE)
SampData<-read.csv("Data/SampleData.csv", header=TRUE)
##Set factor variables
SampData$TimeP<-factor(SampData$TimeP, levels=c("W1", "W2", "M1", "M4", "M8", "M12"), ordered=TRUE)
SampData$Site<-factor(SampData$Site, levels=c("KL", "SS"), ordered=TRUE)
SampData$Genotype<-factor(SampData$Genotype, levels=c("AC8", "AC10", "AC12"), ordered=TRUE)
SampData$Treatment<-factor(SampData$Treatment, levels=c("Control", "Heat"), ordered=TRUE)
SampData$Treat<-factor(SampData$Treat, levels=c("C", "H"), ordered=TRUE)
##Add a Sample Set Variable
SampData$Set<-paste(SampData$TimeP, SampData$Site, SampData$Genotype, SampData$Treat, sep=".")
##Set rownames to ID
rownames(SampData)<-SampData$ID
rownames(Color)<-Color$ID
##Merge Color data with Sample Meta Data
Color<-merge(Color, SampData, all.x=TRUE, all.y=FALSE)
##Add an Analysis Set Variable
Color$AnSet<-"Initial"
Color$AnSet[which(Color$TimeP=="M4" | Color$TimeP== "M8")]<-"Seasonal"
Color$AnSet[which(Color$TimeP=="M12")]<-"Annual"
##Add Season Variable
Color$Season<-"Summer"
Color$Season[which(Color$TimeP=="M4")]<-"Winter"
Color$Season[which(Color$TimeP=="M8")]<-"Spring"
Standardize RGB colors by dividing Coral color by color standards.
Color$Red.Norm.Coral <- Color$Red.Coral/Color$Red.Standard
Color$Green.Norm.Coral <- Color$Green.Coral/Color$Green.Standard
Color$Blue.Norm.Coral <- Color$Blue.Coral/Color$Blue.Standard
#Create matrix of standardized colors
Color.mat <- as.matrix(cbind(Color$Red.Norm.Coral,Color$Green.Norm.Coral,Color$Blue.Norm.Coral))
#Set row names to sample ID
rownames(Color.mat) <- Color$ID
#Create a Distance Matrix for PCA
Color.dist <- vegdist(Color.mat, method="euclidean", na.rm=TRUE)
#Run Principal Components Analysis
Color.PCA <- princomp(Color.dist)
#Initial plot
fviz_pca_ind(Color.PCA)
#Check Variance Explained by Components
summary(Color.PCA)
Importance of components:
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
Standard deviation 5.9664425 2.8510353 0.68377950 0.518671302 0.258287242
Proportion of Variance 0.7965234 0.1818749 0.01046164 0.006019384 0.001492703
Cumulative Proportion 0.7965234 0.9783983 0.98885997 0.994879352 0.996372055
Comp.6 Comp.7 Comp.8 Comp.9
Standard deviation 0.228132003 0.1886893257 0.1249288424 0.1048593795
Proportion of Variance 0.001164502 0.0007966403 0.0003492151 0.0002460267
Cumulative Proportion 0.997536557 0.9983331971 0.9986824122 0.9989284389
Comp.10 Comp.11 Comp.12 Comp.13
Standard deviation 0.0959732912 0.0812139080 0.06894540 6.356276e-02
Proportion of Variance 0.0002060954 0.0001475803 0.00010636 9.040097e-05
Cumulative Proportion 0.9991345344 0.9992821147 0.99938847 9.994789e-01
Comp.14 Comp.15 Comp.16 Comp.17
Standard deviation 5.465842e-02 5.228608e-02 4.240155e-02 0.0405928745
Proportion of Variance 6.684698e-05 6.117018e-05 4.022825e-05 0.0000368695
Cumulative Proportion 9.995457e-01 9.996069e-01 9.996471e-01 0.9996839905
Comp.18 Comp.19 Comp.20 Comp.21
Standard deviation 3.871546e-02 3.223079e-02 3.099237e-02 3.024187e-02
Proportion of Variance 3.353794e-05 2.324394e-05 2.149202e-05 2.046374e-05
Cumulative Proportion 9.997175e-01 9.997408e-01 9.997623e-01 9.997827e-01
Comp.22 Comp.23 Comp.24 Comp.25
Standard deviation 2.913776e-02 2.577596e-02 2.447327e-02 2.240785e-02
Proportion of Variance 1.899678e-05 1.486611e-05 1.340145e-05 1.123487e-05
Cumulative Proportion 9.998017e-01 9.998166e-01 9.998300e-01 9.998412e-01
Comp.26 Comp.27 Comp.28 Comp.29
Standard deviation 2.048258e-02 1.979708e-02 1.961223e-02 1.841620e-02
Proportion of Variance 9.387223e-06 8.769404e-06 8.606402e-06 7.588702e-06
Cumulative Proportion 9.998506e-01 9.998594e-01 9.998680e-01 9.998756e-01
Comp.30 Comp.31 Comp.32 Comp.33
Standard deviation 1.734007e-02 1.650586e-02 1.565251e-02 1.492162e-02
Proportion of Variance 6.727745e-06 6.095986e-06 5.481955e-06 4.981953e-06
Cumulative Proportion 9.998823e-01 9.998884e-01 9.998939e-01 9.998989e-01
Comp.34 Comp.35 Comp.36 Comp.37
Standard deviation 1.477980e-02 1.382765e-02 1.346911e-02 1.296273e-02
Proportion of Variance 4.887703e-06 4.278234e-06 4.059245e-06 3.759764e-06
Cumulative Proportion 9.999038e-01 9.999080e-01 9.999121e-01 9.999159e-01
Comp.38 Comp.39 Comp.40 Comp.41
Standard deviation 1.242438e-02 1.225104e-02 1.202659e-02 1.143600e-02
Proportion of Variance 3.453955e-06 3.358255e-06 3.236327e-06 2.926281e-06
Cumulative Proportion 9.999193e-01 9.999227e-01 9.999259e-01 9.999288e-01
Comp.42 Comp.43 Comp.44 Comp.45
Standard deviation 1.118674e-02 1.083474e-02 1.052343e-02 1.040281e-02
Proportion of Variance 2.800108e-06 2.626666e-06 2.477889e-06 2.421416e-06
Cumulative Proportion 9.999316e-01 9.999343e-01 9.999367e-01 9.999392e-01
Comp.46 Comp.47 Comp.48 Comp.49
Standard deviation 9.968095e-03 9.613069e-03 9.415915e-03 8.777450e-03
Proportion of Variance 2.223269e-06 2.067720e-06 1.983776e-06 1.723869e-06
Cumulative Proportion 9.999414e-01 9.999434e-01 9.999454e-01 9.999472e-01
Comp.50 Comp.51 Comp.52 Comp.53
Standard deviation 8.648309e-03 8.425567e-03 8.355585e-03 8.233017e-03
Proportion of Variance 1.673516e-06 1.588422e-06 1.562145e-06 1.516651e-06
Cumulative Proportion 9.999488e-01 9.999504e-01 9.999520e-01 9.999535e-01
Comp.54 Comp.55 Comp.56 Comp.57
Standard deviation 8.145378e-03 7.928311e-03 7.820005e-03 7.588224e-03
Proportion of Variance 1.484534e-06 1.406465e-06 1.368301e-06 1.288392e-06
Cumulative Proportion 9.999550e-01 9.999564e-01 9.999578e-01 9.999590e-01
Comp.58 Comp.59 Comp.60 Comp.61
Standard deviation 7.399217e-03 7.161826e-03 6.906023e-03 6.744576e-03
Proportion of Variance 1.225009e-06 1.147665e-06 1.067146e-06 1.017834e-06
Cumulative Proportion 9.999603e-01 9.999614e-01 9.999625e-01 9.999635e-01
Comp.62 Comp.63 Comp.64 Comp.65
Standard deviation 6.601241e-03 6.507639e-03 6.320673e-03 6.253688e-03
Proportion of Variance 9.750319e-07 9.475769e-07 8.939109e-07 8.750645e-07
Cumulative Proportion 9.999645e-01 9.999654e-01 9.999663e-01 9.999672e-01
Comp.66 Comp.67 Comp.68 Comp.69
Standard deviation 6.211587e-03 6.116272e-03 6.057045e-03 5.918658e-03
Proportion of Variance 8.633221e-07 8.370303e-07 8.208982e-07 7.838159e-07
Cumulative Proportion 9.999681e-01 9.999689e-01 9.999697e-01 9.999705e-01
Comp.70 Comp.71 Comp.72 Comp.73
Standard deviation 5.785461e-03 5.622312e-03 5.561254e-03 5.357277e-03
Proportion of Variance 7.489341e-07 7.072899e-07 6.920110e-07 6.421785e-07
Cumulative Proportion 9.999712e-01 9.999720e-01 9.999726e-01 9.999733e-01
Comp.74 Comp.75 Comp.76 Comp.77
Standard deviation 5.335074e-03 5.289929e-03 5.209589e-03 5.085456e-03
Proportion of Variance 6.368666e-07 6.261340e-07 6.072599e-07 5.786653e-07
Cumulative Proportion 9.999739e-01 9.999745e-01 9.999752e-01 9.999757e-01
Comp.78 Comp.79 Comp.80 Comp.81
Standard deviation 4.989684e-03 4.838376e-03 4.819534e-03 4.769787e-03
Proportion of Variance 5.570751e-07 5.238017e-07 5.197298e-07 5.090561e-07
Cumulative Proportion 9.999763e-01 9.999768e-01 9.999773e-01 9.999778e-01
Comp.82 Comp.83 Comp.84 Comp.85
Standard deviation 4.684600e-03 4.624466e-03 4.594120e-03 4.554965e-03
Proportion of Variance 4.910352e-07 4.785098e-07 4.722504e-07 4.642348e-07
Cumulative Proportion 9.999783e-01 9.999788e-01 9.999793e-01 9.999797e-01
Comp.86 Comp.87 Comp.88 Comp.89
Standard deviation 4.522164e-03 4.496939e-03 4.314698e-03 4.183138e-03
Proportion of Variance 4.575729e-07 4.524824e-07 4.165513e-07 3.915362e-07
Cumulative Proportion 9.999802e-01 9.999807e-01 9.999811e-01 9.999815e-01
Comp.90 Comp.91 Comp.92 Comp.93
Standard deviation 4.119743e-03 4.086918e-03 4.053485e-03 4.029879e-03
Proportion of Variance 3.797588e-07 3.737313e-07 3.676416e-07 3.633722e-07
Cumulative Proportion 9.999818e-01 9.999822e-01 9.999826e-01 9.999830e-01
Comp.94 Comp.95 Comp.96 Comp.97
Standard deviation 3.971662e-03 3.956274e-03 3.907113e-03 3.837975e-03
Proportion of Variance 3.529492e-07 3.502196e-07 3.415699e-07 3.295884e-07
Cumulative Proportion 9.999833e-01 9.999837e-01 9.999840e-01 9.999843e-01
Comp.98 Comp.99 Comp.100 Comp.101
Standard deviation 3.829425e-03 3.809326e-03 3.774525e-03 3.687694e-03
Proportion of Variance 3.281216e-07 3.246862e-07 3.187809e-07 3.042827e-07
Cumulative Proportion 9.999847e-01 9.999850e-01 9.999853e-01 9.999856e-01
Comp.102 Comp.103 Comp.104 Comp.105
Standard deviation 3.649271e-03 3.619276e-03 3.588033e-03 3.553751e-03
Proportion of Variance 2.979751e-07 2.930967e-07 2.880584e-07 2.825802e-07
Cumulative Proportion 9.999859e-01 9.999862e-01 9.999865e-01 9.999868e-01
Comp.106 Comp.107 Comp.108 Comp.109
Standard deviation 3.471837e-03 3.443214e-03 3.396169e-03 3.352219e-03
Proportion of Variance 2.697034e-07 2.652746e-07 2.580752e-07 2.514388e-07
Cumulative Proportion 9.999870e-01 9.999873e-01 9.999876e-01 9.999878e-01
Comp.110 Comp.111 Comp.112 Comp.113
Standard deviation 3.324612e-03 3.292361e-03 3.267038e-03 3.206243e-03
Proportion of Variance 2.473145e-07 2.425395e-07 2.388229e-07 2.300173e-07
Cumulative Proportion 9.999881e-01 9.999883e-01 9.999885e-01 9.999888e-01
Comp.114 Comp.115 Comp.116 Comp.117
Standard deviation 3.163716e-03 3.148919e-03 3.123593e-03 3.050255e-03
Proportion of Variance 2.239560e-07 2.218659e-07 2.183115e-07 2.081804e-07
Cumulative Proportion 9.999890e-01 9.999892e-01 9.999894e-01 9.999896e-01
Comp.118 Comp.119 Comp.120 Comp.121
Standard deviation 3.048168e-03 3.021563e-03 2.916867e-03 2.905232e-03
Proportion of Variance 2.078957e-07 2.042823e-07 1.903711e-07 1.888553e-07
Cumulative Proportion 9.999898e-01 9.999901e-01 9.999902e-01 9.999904e-01
Comp.122 Comp.123 Comp.124 Comp.125
Standard deviation 2.873967e-03 2.825439e-03 2.783979e-03 2.770090e-03
Proportion of Variance 1.848124e-07 1.786239e-07 1.734201e-07 1.716941e-07
Cumulative Proportion 9.999906e-01 9.999908e-01 9.999910e-01 9.999911e-01
Comp.126 Comp.127 Comp.128 Comp.129
Standard deviation 2.731920e-03 2.715562e-03 2.689263e-03 2.636361e-03
Proportion of Variance 1.669951e-07 1.650012e-07 1.618207e-07 1.555168e-07
Cumulative Proportion 9.999913e-01 9.999915e-01 9.999916e-01 9.999918e-01
Comp.130 Comp.131 Comp.132 Comp.133
Standard deviation 2.631937e-03 2.598599e-03 2.582565e-03 2.576490e-03
Proportion of Variance 1.549953e-07 1.510936e-07 1.492348e-07 1.485335e-07
Cumulative Proportion 9.999919e-01 9.999921e-01 9.999922e-01 9.999924e-01
Comp.134 Comp.135 Comp.136 Comp.137
Standard deviation 2.571974e-03 2.508692e-03 2.468875e-03 2.460109e-03
Proportion of Variance 1.480134e-07 1.408193e-07 1.363848e-07 1.354179e-07
Cumulative Proportion 9.999925e-01 9.999927e-01 9.999928e-01 9.999930e-01
Comp.138 Comp.139 Comp.140 Comp.141
Standard deviation 2.442051e-03 2.420842e-03 2.412396e-03 2.407093e-03
Proportion of Variance 1.334372e-07 1.311295e-07 1.302161e-07 1.296443e-07
Cumulative Proportion 9.999931e-01 9.999932e-01 9.999933e-01 9.999935e-01
Comp.142 Comp.143 Comp.144 Comp.145
Standard deviation 2.389039e-03 2.377346e-03 2.294145e-03 2.256746e-03
Proportion of Variance 1.277069e-07 1.264598e-07 1.177631e-07 1.139548e-07
Cumulative Proportion 9.999936e-01 9.999937e-01 9.999938e-01 9.999940e-01
Comp.146 Comp.147 Comp.148 Comp.149
Standard deviation 2.252202e-03 2.233323e-03 2.228537e-03 2.213427e-03
Proportion of Variance 1.134965e-07 1.116017e-07 1.111239e-07 1.096221e-07
Cumulative Proportion 9.999941e-01 9.999942e-01 9.999943e-01 9.999944e-01
Comp.150 Comp.151 Comp.152 Comp.153
Standard deviation 2.160566e-03 2.153091e-03 2.145484e-03 2.131114e-03
Proportion of Variance 1.044486e-07 1.037271e-07 1.029954e-07 1.016204e-07
Cumulative Proportion 9.999945e-01 9.999946e-01 9.999947e-01 9.999948e-01
Comp.154 Comp.155 Comp.156 Comp.157
Standard deviation 2.119014e-03 2.105134e-03 2.064156e-03 2.059234e-03
Proportion of Variance 1.004697e-07 9.915789e-08 9.533503e-08 9.488099e-08
Cumulative Proportion 9.999949e-01 9.999950e-01 9.999951e-01 9.999952e-01
Comp.158 Comp.159 Comp.160 Comp.161
Standard deviation 2.048058e-03 2.036807e-03 2.010423e-03 1.991899e-03
Proportion of Variance 9.385384e-08 9.282551e-08 9.043627e-08 8.877738e-08
Cumulative Proportion 9.999953e-01 9.999954e-01 9.999955e-01 9.999956e-01
Comp.162 Comp.163 Comp.164 Comp.165
Standard deviation 1.989235e-03 1.984660e-03 1.973171e-03 1.955564e-03
Proportion of Variance 8.854010e-08 8.813328e-08 8.711581e-08 8.556810e-08
Cumulative Proportion 9.999957e-01 9.999958e-01 9.999958e-01 9.999959e-01
Comp.166 Comp.167 Comp.168 Comp.169
Standard deviation 1.943474e-03 1.940369e-03 1.915096e-03 1.907583e-03
Proportion of Variance 8.451331e-08 8.424344e-08 8.206329e-08 8.142065e-08
Cumulative Proportion 9.999960e-01 9.999961e-01 9.999962e-01 9.999963e-01
Comp.170 Comp.171 Comp.172 Comp.173
Standard deviation 1.859351e-03 1.851943e-03 1.837288e-03 1.834061e-03
Proportion of Variance 7.735535e-08 7.674021e-08 7.553047e-08 7.526538e-08
Cumulative Proportion 9.999963e-01 9.999964e-01 9.999965e-01 9.999966e-01
Comp.174 Comp.175 Comp.176 Comp.177
Standard deviation 1.825247e-03 1.802683e-03 1.790922e-03 1.788947e-03
Proportion of Variance 7.454370e-08 7.271201e-08 7.176634e-08 7.160816e-08
Cumulative Proportion 9.999966e-01 9.999967e-01 9.999968e-01 9.999969e-01
Comp.178 Comp.179 Comp.180 Comp.181
Standard deviation 1.778801e-03 1.762585e-03 1.746689e-03 1.735029e-03
Proportion of Variance 7.079824e-08 6.951329e-08 6.826507e-08 6.735674e-08
Cumulative Proportion 9.999969e-01 9.999970e-01 9.999971e-01 9.999971e-01
Comp.182 Comp.183 Comp.184 Comp.185
Standard deviation 1.725138e-03 1.718401e-03 1.706134e-03 1.693086e-03
Proportion of Variance 6.659098e-08 6.607186e-08 6.513196e-08 6.413948e-08
Cumulative Proportion 9.999972e-01 9.999973e-01 9.999973e-01 9.999974e-01
Comp.186 Comp.187 Comp.188 Comp.189
Standard deviation 1.664172e-03 1.652802e-03 1.631724e-03 1.618344e-03
Proportion of Variance 6.196750e-08 6.112365e-08 5.957461e-08 5.860155e-08
Cumulative Proportion 9.999975e-01 9.999975e-01 9.999976e-01 9.999976e-01
Comp.190 Comp.191 Comp.192 Comp.193
Standard deviation 1.609639e-03 1.608006e-03 1.606843e-03 1.597612e-03
Proportion of Variance 5.797286e-08 5.785530e-08 5.777160e-08 5.710975e-08
Cumulative Proportion 9.999977e-01 9.999977e-01 9.999978e-01 9.999979e-01
Comp.194 Comp.195 Comp.196 Comp.197
Standard deviation 1.578069e-03 1.577663e-03 1.533486e-03 1.518076e-03
Proportion of Variance 5.572106e-08 5.569239e-08 5.261712e-08 5.156498e-08
Cumulative Proportion 9.999979e-01 9.999980e-01 9.999980e-01 9.999981e-01
Comp.198 Comp.199 Comp.200 Comp.201
Standard deviation 1.488652e-03 1.474405e-03 1.469552e-03 1.454134e-03
Proportion of Variance 4.958542e-08 4.864089e-08 4.832120e-08 4.731257e-08
Cumulative Proportion 9.999981e-01 9.999982e-01 9.999982e-01 9.999983e-01
Comp.202 Comp.203 Comp.204 Comp.205
Standard deviation 1.449120e-03 1.438415e-03 1.397804e-03 1.393404e-03
Proportion of Variance 4.698688e-08 4.629523e-08 4.371800e-08 4.344321e-08
Cumulative Proportion 9.999983e-01 9.999984e-01 9.999984e-01 9.999985e-01
Comp.206 Comp.207 Comp.208 Comp.209
Standard deviation 1.387434e-03 1.361689e-03 1.353110e-03 1.348979e-03
Proportion of Variance 4.307171e-08 4.148807e-08 4.096698e-08 4.071723e-08
Cumulative Proportion 9.999985e-01 9.999985e-01 9.999986e-01 9.999986e-01
Comp.210 Comp.211 Comp.212 Comp.213
Standard deviation 1.347279e-03 1.336348e-03 1.334581e-03 1.324888e-03
Proportion of Variance 4.061467e-08 3.995828e-08 3.985270e-08 3.927586e-08
Cumulative Proportion 9.999987e-01 9.999987e-01 9.999987e-01 9.999988e-01
Comp.214 Comp.215 Comp.216 Comp.217
Standard deviation 1.311872e-03 1.310251e-03 1.267522e-03 1.264293e-03
Proportion of Variance 3.850794e-08 3.841287e-08 3.594833e-08 3.576542e-08
Cumulative Proportion 9.999988e-01 9.999989e-01 9.999989e-01 9.999989e-01
Comp.218 Comp.219 Comp.220 Comp.221
Standard deviation 1.263446e-03 1.259024e-03 1.241592e-03 1.202814e-03
Proportion of Variance 3.571752e-08 3.546789e-08 3.449257e-08 3.237161e-08
Cumulative Proportion 9.999990e-01 9.999990e-01 9.999990e-01 9.999991e-01
Comp.222 Comp.223 Comp.224 Comp.225
Standard deviation 1.193523e-03 1.171591e-03 1.169104e-03 1.167437e-03
Proportion of Variance 3.187345e-08 3.071280e-08 3.058256e-08 3.049541e-08
Cumulative Proportion 9.999991e-01 9.999991e-01 9.999992e-01 9.999992e-01
Comp.226 Comp.227 Comp.228 Comp.229
Standard deviation 1.147310e-03 1.142949e-03 1.120022e-03 1.115528e-03
Proportion of Variance 2.945299e-08 2.922950e-08 2.806858e-08 2.784381e-08
Cumulative Proportion 9.999992e-01 9.999992e-01 9.999993e-01 9.999993e-01
Comp.230 Comp.231 Comp.232 Comp.233
Standard deviation 1.111854e-03 1.111304e-03 1.095567e-03 1.082954e-03
Proportion of Variance 2.766070e-08 2.763332e-08 2.685626e-08 2.624143e-08
Cumulative Proportion 9.999993e-01 9.999994e-01 9.999994e-01 9.999994e-01
Comp.234 Comp.235 Comp.236 Comp.237
Standard deviation 1.074515e-03 1.053603e-03 1.041945e-03 1.038050e-03
Proportion of Variance 2.583404e-08 2.483829e-08 2.429165e-08 2.411041e-08
Cumulative Proportion 9.999994e-01 9.999995e-01 9.999995e-01 9.999995e-01
Comp.238 Comp.239 Comp.240 Comp.241
Standard deviation 1.028661e-03 1.022137e-03 1.016758e-03 1.004640e-03
Proportion of Variance 2.367621e-08 2.337683e-08 2.313145e-08 2.258334e-08
Cumulative Proportion 9.999995e-01 9.999996e-01 9.999996e-01 9.999996e-01
Comp.242 Comp.243 Comp.244 Comp.245
Standard deviation 9.722268e-04 9.643719e-04 9.623448e-04 9.493652e-04
Proportion of Variance 2.114963e-08 2.080927e-08 2.072187e-08 2.016667e-08
Cumulative Proportion 9.999996e-01 9.999996e-01 9.999997e-01 9.999997e-01
Comp.246 Comp.247 Comp.248 Comp.249
Standard deviation 9.206713e-04 8.938307e-04 8.874138e-04 8.561169e-04
Proportion of Variance 1.896605e-08 1.787632e-08 1.762057e-08 1.639962e-08
Cumulative Proportion 9.999997e-01 9.999997e-01 9.999997e-01 9.999998e-01
Comp.250 Comp.251 Comp.252 Comp.253
Standard deviation 8.301200e-04 8.263898e-04 8.247686e-04 8.111069e-04
Proportion of Variance 1.541876e-08 1.528050e-08 1.522060e-08 1.472054e-08
Cumulative Proportion 9.999998e-01 9.999998e-01 9.999998e-01 9.999998e-01
Comp.254 Comp.255 Comp.256 Comp.257
Standard deviation 7.506775e-04 7.468775e-04 7.386947e-04 7.220588e-04
Proportion of Variance 1.260882e-08 1.248149e-08 1.220949e-08 1.166575e-08
Cumulative Proportion 9.999998e-01 9.999998e-01 9.999999e-01 9.999999e-01
Comp.258 Comp.259 Comp.260 Comp.261
Standard deviation 7.047350e-04 6.826576e-04 6.646714e-04 6.634525e-04
Proportion of Variance 1.111269e-08 1.042734e-08 9.885114e-09 9.848891e-09
Cumulative Proportion 9.999999e-01 9.999999e-01 9.999999e-01 9.999999e-01
Comp.262 Comp.263 Comp.264 Comp.265
Standard deviation 6.549162e-04 6.417443e-04 6.258298e-04 6.132098e-04
Proportion of Variance 9.597080e-09 9.214921e-09 8.763550e-09 8.413677e-09
Cumulative Proportion 9.999999e-01 9.999999e-01 9.999999e-01 9.999999e-01
Comp.266 Comp.267 Comp.268 Comp.269
Standard deviation 6.083387e-04 5.619286e-04 5.606398e-04 4.978484e-04
Proportion of Variance 8.280538e-09 7.065289e-09 7.032916e-09 5.545769e-09
Cumulative Proportion 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00
Comp.270 Comp.271 Comp.272 Comp.273
Standard deviation 4.834326e-04 4.691742e-04 4.667486e-04 3.909267e-04
Proportion of Variance 5.229251e-09 4.925335e-09 4.874541e-09 3.419465e-09
Cumulative Proportion 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00
Comp.274 Comp.275 Comp.276 Comp.277
Standard deviation 3.401131e-04 3.345836e-04 3.329745e-04 0
Proportion of Variance 2.588299e-09 2.504822e-09 2.480787e-09 0
Cumulative Proportion 1.000000e+00 1.000000e+00 1.000000e+00 1
#Visualize the importance of each principal component
fviz_eig(Color.PCA, addlabels = TRUE)
PC1 Explains 79.7% of the variance in the color data.
#% Variance PCA 1
PC1<-sprintf("%1.2f",0.7965234*100)
PC1
[1] "79.65"
#% Variance PCA 2
PC2<-sprintf("%1.2f",0.1818749*100)
PC2
[1] "18.19"
#Prepare for Plotting
Color.PCA_scores <- as.data.frame(Color.PCA$scores[,c(1:2)])
Color.PCA_scores$ID<-rownames(Color.PCA_scores)
Color.PCA_scores<-merge(Color.PCA_scores, SampData)
#Plot PCA
Color.PCA.plot<-ggplot(data = Color.PCA_scores, aes(x = Comp.1, y = Comp.2)) +
geom_point(data = Color.PCA_scores, aes(colour = Treatment), size = point.sz-1, alpha = 0.8) +
scale_colour_manual(values =HC.colors.o)+
theme_classic()+
scale_x_continuous(limits = c(-6, 12))+
scale_y_continuous(limits = c(-9, 9))+
labs(x=paste0('PC 1 (',PC1,"%)"), y=paste0('PC 2 (',PC2,"%)"))+
theme(axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="top");Color.PCA.plot
Samples align along PC1 according to Treatment (Heated vs Control). Coordinates along PC1 will be extracted as the Color Score (explains 79.7% of the variance in the color data). Coordinates will multiplied by -1 for intuitive interpretation (Control > Heated) then made positive by adding 20
##Retain Metadata columns of interest
names(Color.PCA_scores)
[1] "ID" "Comp.1" "Comp.2" "RandN" "TimeP" "Site"
[7] "Genotype" "Treat" "Treatment" "Vol_ml" "Wax.I_g" "Wax.F_g"
[13] "Set"
ColorData<-Color.PCA_scores[,c(1,4:9,13)]
##Retain PC1 as Color Score
ColorData$Score_Full<-Color.PCA_scores$Comp.1
##Initial Visual Check
ggplot(ColorData, aes(x=Set, y=Score_Full)) +
geom_boxplot(alpha=0.5, shape=2, outlier.shape = NA)+
geom_jitter(shape=16, position=position_jitter(0.1))+
theme(axis.text.x = element_text(angle = 90))
##Invert signs for Control > Heated
ColorData$Score_Full<-ColorData$Score_Full*(-1)
#Adding 20 to make all score values positive
ColorData$Score_Full<- ColorData$Score_Full +20
##Initial Visual Check
ggplot(ColorData, aes(x=Set, y=Score_Full)) +
geom_boxplot(alpha=0.5, shape=2, outlier.shape = NA)+
geom_jitter(shape=16, position=position_jitter(0.1))+
theme(axis.text.x = element_text(angle = 90))
##Plot by Treatment
ggplot(ColorData, aes(x=Treatment, y=Score_Full)) +
geom_boxplot(alpha=0.5, shape=2, outlier.shape = NA)+
geom_jitter(shape=16, position=position_jitter(0.1))+
theme(axis.text.x = element_text(angle = 90))
Repeat the calculation of Color Score for each Timepoint individually
#Subset W1 Timepoint
Color_W1<-subset(Color, TimeP=="W1")
#Create matrix of standardized colors
Color_W1.mat <- as.matrix(cbind(Color_W1$Red.Norm.Coral,Color_W1$Green.Norm.Coral,Color_W1$Blue.Norm.Coral))
#Set row names to sample ID
rownames(Color_W1.mat) <- Color_W1$ID
#Create a Distance Matrix for PCA
Color_W1.dist <- vegdist(Color_W1.mat, method="euclidean", na.rm=TRUE)
#Run Principal Components Analysis
Color_W1.PCA <- princomp(Color_W1.dist)
#Initial plot
fviz_pca_ind(Color_W1.PCA)
#Check Variance Explained by Components
summary(Color_W1.PCA)
Importance of components:
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
Standard deviation 2.1086566 1.0032761 0.25961776 0.196208135 0.141338625
Proportion of Variance 0.7922463 0.1793451 0.01200929 0.006859343 0.003559346
Cumulative Proportion 0.7922463 0.9715914 0.98360067 0.990460018 0.994019365
Comp.6 Comp.7 Comp.8 Comp.9
Standard deviation 0.102314050 0.0627331568 0.0608328509 0.0516031555
Proportion of Variance 0.001865173 0.0007012014 0.0006593634 0.0004744616
Cumulative Proportion 0.995884537 0.9965857387 0.9972451022 0.9977195637
Comp.10 Comp.11 Comp.12 Comp.13
Standard deviation 0.044076898 0.0431571169 0.0354515030 0.0347047544
Proportion of Variance 0.000346155 0.0003318588 0.0002239329 0.0002145984
Cumulative Proportion 0.998065719 0.9983975775 0.9986215104 0.9988361088
Comp.14 Comp.15 Comp.16 Comp.17
Standard deviation 0.0309601659 0.0279451927 0.0267165909 2.265396e-02
Proportion of Variance 0.0001707871 0.0001391434 0.0001271776 9.144013e-05
Cumulative Proportion 0.9990068959 0.9991460393 0.9992732169 9.993647e-01
Comp.18 Comp.19 Comp.20 Comp.21
Standard deviation 2.123310e-02 2.017703e-02 1.952956e-02 1.736587e-02
Proportion of Variance 8.032957e-05 7.253757e-05 6.795687e-05 5.373306e-05
Cumulative Proportion 9.994450e-01 9.995175e-01 9.995855e-01 9.996392e-01
Comp.22 Comp.23 Comp.24 Comp.25
Standard deviation 1.619615e-02 1.542738e-02 1.375474e-02 1.317188e-02
Proportion of Variance 4.673824e-05 4.240655e-05 3.370956e-05 3.091321e-05
Cumulative Proportion 9.996860e-01 9.997284e-01 9.997621e-01 9.997930e-01
Comp.26 Comp.27 Comp.28 Comp.29
Standard deviation 0.0128109337 0.011254397 1.088926e-02 0.0106737054
Proportion of Variance 0.0000292422 0.000022568 2.112736e-05 0.0000202992
Cumulative Proportion 0.9998222239 0.999844792 9.998659e-01 0.9998862184
Comp.30 Comp.31 Comp.32 Comp.33
Standard deviation 9.942582e-03 0.0089965270 0.0084877761 0.0082860852
Proportion of Variance 1.761355e-05 0.0000144211 0.0000128362 0.0000122334
Cumulative Proportion 9.999038e-01 0.9999182531 0.9999310893 0.9999433227
Comp.34 Comp.35 Comp.36 Comp.37
Standard deviation 7.755027e-03 7.357170e-03 6.973448e-03 6.840233e-03
Proportion of Variance 1.071557e-05 9.644288e-06 8.664502e-06 8.336627e-06
Cumulative Proportion 9.999540e-01 9.999637e-01 9.999723e-01 9.999807e-01
Comp.38 Comp.39 Comp.40 Comp.41
Standard deviation 6.656542e-03 6.264577e-03 3.991039e-03 2.988127e-03
Proportion of Variance 7.894887e-06 6.992492e-06 2.838052e-06 1.590914e-06
Cumulative Proportion 9.999886e-01 9.999956e-01 9.999984e-01 1.000000e+00
Comp.42
Standard deviation 0
Proportion of Variance 0
Cumulative Proportion 1
#Visualize the importance of each principal component
fviz_eig(Color_W1.PCA, addlabels = TRUE)
PC1 Explains 79.2% of the variance in the color data.
#% Variance PCA 1
PC1_W1<-sprintf("%1.2f",0.7922463*100)
PC1_W1
[1] "79.22"
#% Variance PCA 2
PC2_W1<-sprintf("%1.2f",0.1793451*100)
PC2_W1
[1] "17.93"
#Prepare for Plotting
Color_W1.PCA_scores <- as.data.frame(Color_W1.PCA$scores[,c(1:2)])
Color_W1.PCA_scores$ID<-rownames(Color_W1.PCA_scores)
Color_W1.PCA_scores<-merge(Color_W1.PCA_scores, SampData)
#Plot PCA
Color_W1.PCA.plot<-ggplot(data = Color_W1.PCA_scores, aes(x = Comp.1, y = Comp.2)) +
geom_point(data = Color_W1.PCA_scores, aes(colour = Treatment), size = point.sz-1, alpha = 0.8) +
scale_colour_manual(values =HC.colors.o)+
theme_classic()+
scale_x_continuous(limits = c(-6, 12))+
scale_y_continuous(limits = c(-9, 9))+
labs(x=paste0('PC 1 (',PC1_W1,"%)"), y=paste0('PC 2 (',PC2_W1,"%)"))+
theme(axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="top");Color_W1.PCA.plot
Samples align along PC1 according to Treatment (Heated vs Control). Coordinates along PC1 will be extracted as the Color Score. Coordinates will multiplied by -1 for intuitive interpretation (Control > Heated) then made positive by adding 20
#Subset W2 Timepoint
Color_W2<-subset(Color, TimeP=="W2")
#Create matrix of standardized colors
Color_W2.mat <- as.matrix(cbind(Color_W2$Red.Norm.Coral,Color_W2$Green.Norm.Coral,Color_W2$Blue.Norm.Coral))
#Set row names to sample ID
rownames(Color_W2.mat) <- Color_W2$ID
#Create a Distance Matrix for PCA
Color_W2.dist <- vegdist(Color_W2.mat, method="euclidean", na.rm=TRUE)
#Run Principal Components Analysis
Color_W2.PCA <- princomp(Color_W2.dist)
#Initial plot
fviz_pca_ind(Color_W2.PCA)
#Check Variance Explained by Components
summary(Color_W2.PCA)
Importance of components:
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
Standard deviation 2.3552985 1.1413264 0.33060589 0.174140577 0.095153156
Proportion of Variance 0.7899334 0.1854891 0.01556395 0.004318158 0.001289273
Cumulative Proportion 0.7899334 0.9754225 0.99098642 0.995304582 0.996593855
Comp.6 Comp.7 Comp.8 Comp.9
Standard deviation 0.086557371 0.0803894617 0.0462236633 0.0403168626
Proportion of Variance 0.001066858 0.0009202309 0.0003042477 0.0002314579
Cumulative Proportion 0.997660714 0.9985809445 0.9988851922 0.9991166501
Comp.10 Comp.11 Comp.12 Comp.13
Standard deviation 0.0376376806 2.632705e-02 2.496879e-02 2.086078e-02
Proportion of Variance 0.0002017178 9.869679e-05 8.877561e-05 6.196691e-05
Cumulative Proportion 0.9993183680 9.994171e-01 9.995058e-01 9.995678e-01
Comp.14 Comp.15 Comp.16 Comp.17
Standard deviation 1.904118e-02 1.639261e-02 1.625494e-02 1.515508e-02
Proportion of Variance 5.162813e-05 3.826439e-05 3.762437e-05 3.270507e-05
Cumulative Proportion 9.996194e-01 9.996577e-01 9.996953e-01 9.997280e-01
Comp.18 Comp.19 Comp.20 Comp.21
Standard deviation 1.412499e-02 1.345800e-02 1.291583e-02 1.180588e-02
Proportion of Variance 2.841023e-05 2.579049e-05 2.375437e-05 1.984702e-05
Cumulative Proportion 9.997564e-01 9.997822e-01 9.998060e-01 9.998258e-01
Comp.22 Comp.23 Comp.24 Comp.25
Standard deviation 1.084875e-02 1.052100e-02 1.003868e-02 9.874342e-03
Proportion of Variance 1.675938e-05 1.576206e-05 1.434998e-05 1.388401e-05
Cumulative Proportion 9.998426e-01 9.998584e-01 9.998727e-01 9.998866e-01
Comp.26 Comp.27 Comp.28 Comp.29
Standard deviation 9.579537e-03 9.236945e-03 8.896153e-03 8.432389e-03
Proportion of Variance 1.306735e-05 1.214941e-05 1.126946e-05 1.012511e-05
Cumulative Proportion 9.998997e-01 9.999118e-01 9.999231e-01 9.999332e-01
Comp.30 Comp.31 Comp.32 Comp.33
Standard deviation 7.911581e-03 7.208763e-03 6.792079e-03 6.379183e-03
Proportion of Variance 8.913026e-06 7.399802e-06 6.569072e-06 5.794670e-06
Cumulative Proportion 9.999421e-01 9.999495e-01 9.999561e-01 9.999619e-01
Comp.34 Comp.35 Comp.36 Comp.37
Standard deviation 5.960964e-03 5.591949e-03 5.357038e-03 5.201265e-03
Proportion of Variance 5.059779e-06 4.452717e-06 4.086467e-06 3.852268e-06
Cumulative Proportion 9.999669e-01 9.999714e-01 9.999755e-01 9.999793e-01
Comp.38 Comp.39 Comp.40 Comp.41
Standard deviation 4.973003e-03 4.651363e-03 4.494040e-03 4.357619e-03
Proportion of Variance 3.521567e-06 3.080768e-06 2.875891e-06 2.703940e-06
Cumulative Proportion 9.999828e-01 9.999859e-01 9.999888e-01 9.999915e-01
Comp.42 Comp.43 Comp.44 Comp.45
Standard deviation 4.243583e-03 3.529546e-03 3.192298e-03 3.099115e-03
Proportion of Variance 2.564272e-06 1.773930e-06 1.451127e-06 1.367647e-06
Cumulative Proportion 9.999941e-01 9.999958e-01 9.999973e-01 9.999987e-01
Comp.46 Comp.47
Standard deviation 3.061869e-03 8.056914e-09
Proportion of Variance 1.334970e-06 9.243491e-18
Cumulative Proportion 1.000000e+00 1.000000e+00
#Visualize the importance of each principal component
fviz_eig(Color_W2.PCA, addlabels = TRUE)
PC1 Explains 79% of the variance in the color data.
#% Variance PCA 1
PC1_W2<-sprintf("%1.2f",0.7899334*100)
PC1_W2
[1] "78.99"
#% Variance PCA 2
PC2_W2<-sprintf("%1.2f",0.1854891*100)
PC2_W2
[1] "18.55"
#Prepare for Plotting
Color_W2.PCA_scores <- as.data.frame(Color_W2.PCA$scores[,c(1:2)])
Color_W2.PCA_scores$ID<-rownames(Color_W2.PCA_scores)
Color_W2.PCA_scores<-merge(Color_W2.PCA_scores, SampData)
#Plot PCA
Color_W2.PCA.plot<-ggplot(data = Color_W2.PCA_scores, aes(x = Comp.1, y = Comp.2)) +
geom_point(data = Color_W2.PCA_scores, aes(colour = Treatment), size = point.sz-1, alpha = 0.8) +
scale_colour_manual(values =HC.colors.o)+
theme_classic()+
scale_x_continuous(limits = c(-6, 12))+
scale_y_continuous(limits = c(-9, 9))+
labs(x=paste0('PC 1 (',PC1_W2,"%)"), y=paste0('PC 2 (',PC2_W2,"%)"))+
theme(axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="top");Color_W2.PCA.plot
Samples align along PC1 according to Treatment (Heated vs Control). Coordinates along PC1 will be extracted as the Color Score. Coordinates will multiplied by -1 for intuitive interpretation (Control > Heated) then made positive by adding 20
#Subset M1 Timepoint
Color_M1<-subset(Color, TimeP=="M1")
#Create matrix of standardized colors
Color_M1.mat <- as.matrix(cbind(Color_M1$Red.Norm.Coral,Color_M1$Green.Norm.Coral,Color_M1$Blue.Norm.Coral))
#Set row names to sample ID
rownames(Color_M1.mat) <- Color_M1$ID
#Create a Distance Matrix for PCA
Color_M1.dist <- vegdist(Color_M1.mat, method="euclidean", na.rm=TRUE)
#Run Principal Components Analysis
Color_M1.PCA <- princomp(Color_M1.dist)
#Initial plot
fviz_pca_ind(Color_M1.PCA)
#Check Variance Explained by Components
summary(Color_M1.PCA)
Importance of components:
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
Standard deviation 2.0285708 0.7976034 0.22431251 0.163467489 0.075598397
Proportion of Variance 0.8482496 0.1311346 0.01037171 0.005508155 0.001178063
Cumulative Proportion 0.8482496 0.9793842 0.98975592 0.995264074 0.996442137
Comp.6 Comp.7 Comp.8 Comp.9
Standard deviation 0.0632784913 0.0583479718 0.0403731895 0.0388093762
Proportion of Variance 0.0008253831 0.0007017701 0.0003359924 0.0003104679
Cumulative Proportion 0.9972675197 0.9979692898 0.9983052822 0.9986157501
Comp.10 Comp.11 Comp.12 Comp.13
Standard deviation 0.0336945833 0.0307748838 0.0275274774 0.0237690746
Proportion of Variance 0.0002340257 0.0001952253 0.0001561982 0.0001164576
Cumulative Proportion 0.9988497758 0.9990450011 0.9992011993 0.9993176569
Comp.14 Comp.15 Comp.16 Comp.17
Standard deviation 0.0224549289 2.012014e-02 1.902218e-02 1.760162e-02
Proportion of Variance 0.0001039362 8.344593e-05 7.458713e-05 6.386291e-05
Cumulative Proportion 0.9994215931 9.995050e-01 9.995796e-01 9.996435e-01
Comp.18 Comp.19 Comp.20 Comp.21
Standard deviation 1.553573e-02 1.313256e-02 1.244459e-02 1.183515e-02
Proportion of Variance 4.975154e-05 3.555021e-05 3.192305e-05 2.887292e-05
Cumulative Proportion 9.996932e-01 9.997288e-01 9.997607e-01 9.997896e-01
Comp.22 Comp.23 Comp.24 Comp.25
Standard deviation 1.150007e-02 1.060741e-02 1.037989e-02 9.249358e-03
Proportion of Variance 2.726114e-05 2.319327e-05 2.220901e-05 1.763464e-05
Cumulative Proportion 9.998168e-01 9.998400e-01 9.998623e-01 9.998799e-01
Comp.26 Comp.27 Comp.28 Comp.29
Standard deviation 8.784558e-03 8.581892e-03 0.0080282734 7.080712e-03
Proportion of Variance 1.590681e-05 1.518132e-05 0.0000132858 1.033468e-05
Cumulative Proportion 9.998958e-01 9.999110e-01 0.9999242588 9.999346e-01
Comp.30 Comp.31 Comp.32 Comp.33
Standard deviation 6.761799e-03 6.355545e-03 6.007771e-03 5.938046e-03
Proportion of Variance 9.424705e-06 8.326239e-06 7.439952e-06 7.268260e-06
Cumulative Proportion 9.999440e-01 9.999523e-01 9.999598e-01 9.999671e-01
Comp.34 Comp.35 Comp.36 Comp.37
Standard deviation 5.588981e-03 5.372683e-03 4.937974e-03 4.789632e-03
Proportion of Variance 6.438855e-06 5.950121e-06 5.026213e-06 4.728764e-06
Cumulative Proportion 9.999735e-01 9.999794e-01 9.999845e-01 9.999892e-01
Comp.38 Comp.39 Comp.40 Comp.41
Standard deviation 4.348942e-03 3.069729e-03 2.821410e-03 2.693993e-03
Proportion of Variance 3.898616e-06 1.942421e-06 1.640876e-06 1.496016e-06
Cumulative Proportion 9.999931e-01 9.999950e-01 9.999967e-01 9.999982e-01
Comp.42 Comp.43 Comp.44
Standard deviation 2.279108e-03 1.913536e-03 0
Proportion of Variance 1.070713e-06 7.547733e-07 0
Cumulative Proportion 9.999992e-01 1.000000e+00 1
#Visualize the importance of each principal component
fviz_eig(Color_M1.PCA, addlabels = TRUE)
PC1 Explains 84.8% of the variance in the color data.
#% Variance PCA 1
PC1_M1<-sprintf("%1.2f",0.8482496 *100)
PC1_M1
[1] "84.82"
#% Variance PCA 2
PC2_M1<-sprintf("%1.2f",0.1311346 *100)
PC2_M1
[1] "13.11"
#Prepare for Plotting
Color_M1.PCA_scores <- as.data.frame(Color_M1.PCA$scores[,c(1:2)])
Color_M1.PCA_scores$ID<-rownames(Color_M1.PCA_scores)
Color_M1.PCA_scores<-merge(Color_M1.PCA_scores, SampData)
#Plot PCA
Color_M1.PCA.plot<-ggplot(data = Color_M1.PCA_scores, aes(x = Comp.1, y = Comp.2)) +
geom_point(data = Color_M1.PCA_scores, aes(colour = Treatment), size = point.sz-1, alpha = 0.8) +
scale_colour_manual(values =HC.colors.o)+
theme_classic()+
scale_x_continuous(limits = c(-6, 12))+
scale_y_continuous(limits = c(-9, 9))+
labs(x=paste0('PC 1 (',PC1_M1,"%)"), y=paste0('PC 2 (',PC2_M1,"%)"))+
theme(axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="top");Color_M1.PCA.plot
Samples align along PC1 according to Treatment (Heated vs Control). Coordinates along PC1 will be extracted as the Color Score. Coordinates will multiplied by -1 for intuitive interpretation (Control > Heated) then made positive by adding 20
#Subset M4 Timepoint
Color_M4<-subset(Color, TimeP=="M4")
#Create matrix of standardized colors
Color_M4.mat <- as.matrix(cbind(Color_M4$Red.Norm.Coral,Color_M4$Green.Norm.Coral,Color_M4$Blue.Norm.Coral))
#Set row names to sample ID
rownames(Color_M4.mat) <- Color_M4$ID
#Create a Distance Matrix for PCA
Color_M4.dist <- vegdist(Color_M4.mat, method="euclidean", na.rm=TRUE)
#Run Principal Components Analysis
Color_M4.PCA <- princomp(Color_M4.dist)
#Initial plot
fviz_pca_ind(Color_M4.PCA)
#Check Variance Explained by Components
summary(Color_M4.PCA)
Importance of components:
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
Standard deviation 1.2309346 0.7018463 0.15366039 0.120048435 0.093361902
Proportion of Variance 0.7338452 0.2385715 0.01143558 0.006979873 0.004221569
Cumulative Proportion 0.7338452 0.9724167 0.98385224 0.990832109 0.995053678
Comp.6 Comp.7 Comp.8 Comp.9
Standard deviation 0.053096900 0.038343465 0.0330487379 0.0287023366
Proportion of Variance 0.001365441 0.000712061 0.0005289861 0.0003989964
Cumulative Proportion 0.996419119 0.997131180 0.9976601659 0.9980591623
Comp.10 Comp.11 Comp.12 Comp.13
Standard deviation 0.0248875165 0.0238476306 0.0214482809 0.0184060325
Proportion of Variance 0.0002999837 0.0002754387 0.0002228022 0.0001640797
Cumulative Proportion 0.9983591460 0.9986345847 0.9988573869 0.9990214666
Comp.14 Comp.15 Comp.16 Comp.17
Standard deviation 0.0175464260 1.383209e-02 1.305697e-02 1.233098e-02
Proportion of Variance 0.0001491117 9.266378e-05 8.256949e-05 7.364273e-05
Cumulative Proportion 0.9991705783 9.992632e-01 9.993458e-01 9.994195e-01
Comp.18 Comp.19 Comp.20 Comp.21
Standard deviation 1.226782e-02 1.080529e-02 1.019493e-02 9.936816e-03
Proportion of Variance 7.289026e-05 5.654668e-05 5.033883e-05 4.782214e-05
Cumulative Proportion 9.994923e-01 9.995489e-01 9.995992e-01 9.996471e-01
Comp.22 Comp.23 Comp.24 Comp.25
Standard deviation 0.0088345025 8.167480e-03 7.928379e-03 7.367121e-03
Proportion of Variance 0.0000378006 3.230805e-05 3.044411e-05 2.628634e-05
Cumulative Proportion 0.9996848528 9.997172e-01 9.997476e-01 9.997739e-01
Comp.26 Comp.27 Comp.28 Comp.29
Standard deviation 7.331757e-03 6.472753e-03 6.268150e-03 6.116798e-03
Proportion of Variance 2.603458e-05 2.029143e-05 1.902888e-05 1.812102e-05
Cumulative Proportion 9.997999e-01 9.998202e-01 9.998392e-01 9.998574e-01
Comp.30 Comp.31 Comp.32 Comp.33
Standard deviation 5.943301e-03 5.841620e-03 5.272834e-03 5.248384e-03
Proportion of Variance 1.710763e-05 1.652727e-05 1.346551e-05 1.334092e-05
Cumulative Proportion 9.998745e-01 9.998910e-01 9.999045e-01 9.999178e-01
Comp.34 Comp.35 Comp.36 Comp.37
Standard deviation 4.566595e-03 4.468233e-03 4.438093e-03 4.176434e-03
Proportion of Variance 1.009995e-05 9.669546e-06 9.539537e-06 8.447840e-06
Cumulative Proportion 9.999279e-01 9.999376e-01 9.999471e-01 9.999556e-01
Comp.38 Comp.39 Comp.40 Comp.41
Standard deviation 3.945923e-03 3.913443e-03 3.737298e-03 3.495544e-03
Proportion of Variance 7.541048e-06 7.417413e-06 6.764723e-06 5.917851e-06
Cumulative Proportion 9.999631e-01 9.999705e-01 9.999773e-01 9.999832e-01
Comp.42 Comp.43 Comp.44 Comp.45
Standard deviation 3.278510e-03 3.203026e-03 2.732893e-03 1.845243e-03
Proportion of Variance 5.205802e-06 4.968844e-06 3.617262e-06 1.649080e-06
Cumulative Proportion 9.999884e-01 9.999934e-01 9.999970e-01 9.999986e-01
Comp.46 Comp.47 Comp.48
Standard deviation 1.461483e-03 8.103806e-04 0
Proportion of Variance 1.034480e-06 3.180626e-07 0
Cumulative Proportion 9.999997e-01 1.000000e+00 1
#Visualize the importance of each principal component
fviz_eig(Color_M4.PCA, addlabels = TRUE)
PC1 Explains 73.4% of the variance in the color data.
#% Variance PCA 1
PC1_M4<-sprintf("%1.2f",0.7338452 *100)
PC1_M4
[1] "73.38"
#% Variance PCA 2
PC2_M4<-sprintf("%1.2f",0.2385715*100)
PC2_M4
[1] "23.86"
#Prepare for Plotting
Color_M4.PCA_scores <- as.data.frame(Color_M4.PCA$scores[,c(1:2)])
Color_M4.PCA_scores$ID<-rownames(Color_M4.PCA_scores)
Color_M4.PCA_scores<-merge(Color_M4.PCA_scores, SampData)
#Plot PCA
Color_M4.PCA.plot<-ggplot(data = Color_M4.PCA_scores, aes(x = Comp.1, y = Comp.2)) +
geom_point(data = Color_M4.PCA_scores, aes(colour = Treatment), size = point.sz-1, alpha = 0.8) +
scale_colour_manual(values =HC.colors.o)+
theme_classic()+
scale_x_continuous(limits = c(-6, 12))+
scale_y_continuous(limits = c(-9, 9))+
labs(x=paste0('PC 1 (',PC1_M4,"%)"), y=paste0('PC 2 (',PC2_M4,"%)"))+
theme(axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="top");Color_M4.PCA.plot
Samples align along PC1 according to Treatment (Heated vs Control). Coordinates along PC1 will be extracted as the Color Score. *Note: These coordinates should not be multiplied by -1 for intuitive interpretation (Control > Heated), but will still be made positive by adding 20
#Subset W1 Timepoint
Color_M8<-subset(Color, TimeP=="M8")
#Create matrix of standardized colors
Color_M8.mat <- as.matrix(cbind(Color_M8$Red.Norm.Coral,Color_M8$Green.Norm.Coral,Color_M8$Blue.Norm.Coral))
#Set row names to sample ID
rownames(Color_M8.mat) <- Color_M8$ID
#Create a Distance Matrix for PCA
Color_M8.dist <- vegdist(Color_M8.mat, method="euclidean", na.rm=TRUE)
#Run Principal Components Analysis
Color_M8.PCA <- princomp(Color_M8.dist)
#Initial plot
fviz_pca_ind(Color_M8.PCA)
#Check Variance Explained by Components
summary(Color_M8.PCA)
Importance of components:
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
Standard deviation 0.8098439 0.4333088 0.09461894 0.06515443 0.058919229
Proportion of Variance 0.7569193 0.2166915 0.01033245 0.00489931 0.004006463
Cumulative Proportion 0.7569193 0.9736108 0.98394326 0.98884257 0.992849031
Comp.6 Comp.7 Comp.8 Comp.9
Standard deviation 0.044077309 0.0308445 0.0246012130 0.0242826222
Proportion of Variance 0.002242214 0.0010980 0.0006984897 0.0006805157
Cumulative Proportion 0.995091245 0.9961892 0.9968877348 0.9975682505
Comp.10 Comp.11 Comp.12 Comp.13
Standard deviation 0.0184116841 0.0161493736 0.0142114594 0.0137494920
Proportion of Variance 0.0003912317 0.0003009944 0.0002330904 0.0002181827
Cumulative Proportion 0.9979594822 0.9982604765 0.9984935669 0.9987117496
Comp.14 Comp.15 Comp.16 Comp.17
Standard deviation 0.011334062 0.0109649690 0.0094676980 9.159072e-03
Proportion of Variance 0.000148258 0.0001387592 0.0001034513 9.681663e-05
Cumulative Proportion 0.998860008 0.9989987668 0.9991022181 9.991990e-01
Comp.18 Comp.19 Comp.20 Comp.21
Standard deviation 8.495106e-03 7.763228e-03 7.701411e-03 7.064981e-03
Proportion of Variance 8.328842e-05 6.955553e-05 6.845222e-05 5.760617e-05
Cumulative Proportion 9.992823e-01 9.993519e-01 9.994203e-01 9.994779e-01
Comp.22 Comp.23 Comp.24 Comp.25
Standard deviation 6.725859e-03 6.558260e-03 6.153358e-03 5.552261e-03
Proportion of Variance 5.220866e-05 4.963914e-05 4.369899e-05 3.557843e-05
Cumulative Proportion 9.995301e-01 9.995798e-01 9.996235e-01 9.996591e-01
Comp.26 Comp.27 Comp.28 Comp.29
Standard deviation 5.168112e-03 5.026726e-03 4.861890e-03 4.644134e-03
Proportion of Variance 3.082555e-05 2.916201e-05 2.728081e-05 2.489181e-05
Cumulative Proportion 9.996899e-01 9.997190e-01 9.997463e-01 9.997712e-01
Comp.30 Comp.31 Comp.32 Comp.33
Standard deviation 4.538340e-03 4.270442e-03 4.189387e-03 4.088007e-03
Proportion of Variance 2.377065e-05 2.104712e-05 2.025574e-05 1.928725e-05
Cumulative Proportion 9.997950e-01 9.998160e-01 9.998363e-01 9.998556e-01
Comp.34 Comp.35 Comp.36 Comp.37
Standard deviation 0.0039213027 3.808023e-03 3.674472e-03 0.003562953
Proportion of Variance 0.0000177463 1.673579e-05 1.558249e-05 0.000014651
Cumulative Proportion 0.9998733295 9.998901e-01 9.999056e-01 0.999920299
Comp.38 Comp.39 Comp.40 Comp.41
Standard deviation 3.532163e-03 0.0033427124 3.257387e-03 3.131059e-03
Proportion of Variance 1.439887e-05 0.0000128957 1.224576e-05 1.131435e-05
Cumulative Proportion 9.999347e-01 0.9999475933 9.999598e-01 9.999712e-01
Comp.42 Comp.43 Comp.44 Comp.45
Standard deviation 2.405568e-03 2.325405e-03 2.170286e-03 1.993345e-03
Proportion of Variance 6.678552e-06 6.240856e-06 5.436017e-06 4.585768e-06
Cumulative Proportion 9.999778e-01 9.999841e-01 9.999895e-01 9.999941e-01
Comp.46 Comp.47 Comp.48
Standard deviation 1.900185e-03 1.227238e-03 0
Proportion of Variance 4.167147e-06 1.738219e-06 0
Cumulative Proportion 9.999983e-01 1.000000e+00 1
#Visualize the importance of each principal component
fviz_eig(Color_M8.PCA, addlabels = TRUE)
PC1 Explains 75.7% of the variance in the color data.
#% Variance PCA 1
PC1_M8<-sprintf("%1.2f",0.7569193*100)
PC1_M8
[1] "75.69"
#% Variance PCA 2
PC2_M8<-sprintf("%1.2f",0.2166915 *100)
PC2_M8
[1] "21.67"
#Prepare for Plotting
Color_M8.PCA_scores <- as.data.frame(Color_M8.PCA$scores[,c(1:2)])
Color_M8.PCA_scores$ID<-rownames(Color_M8.PCA_scores)
Color_M8.PCA_scores<-merge(Color_M8.PCA_scores, SampData)
#Plot PCA
Color_M8.PCA.plot<-ggplot(data = Color_M8.PCA_scores, aes(x = Comp.1, y = Comp.2)) +
geom_point(data = Color_M8.PCA_scores, aes(colour = Treatment), size = point.sz-1, alpha = 0.8) +
scale_colour_manual(values =HC.colors.o)+
theme_classic()+
scale_x_continuous(limits = c(-6, 12))+
scale_y_continuous(limits = c(-9, 9))+
labs(x=paste0('PC 1 (',PC1_M8,"%)"), y=paste0('PC 2 (',PC2_M8,"%)"))+
theme(axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="top");Color_M8.PCA.plot
Samples align along PC1 according to Treatment, but less separation between Heated vs Control. Coordinates along PC1 will be extracted as the Color Score. Coordinates will multiplied by -1 for intuitive interpretation (Control > Heated) then made positive by adding 20
#Subset M12 Timepoint
Color_M12<-subset(Color, TimeP=="M12")
#Create matrix of standardized colors
Color_M12.mat <- as.matrix(cbind(Color_M12$Red.Norm.Coral,Color_M12$Green.Norm.Coral,Color_M12$Blue.Norm.Coral))
#Set row names to sample ID
rownames(Color_M12.mat) <- Color_M12$ID
#Create a Distance Matrix for PCA
Color_M12.dist <- vegdist(Color_M12.mat, method="euclidean", na.rm=TRUE)
#Run Principal Components Analysis
Color_M12.PCA <- princomp(Color_M12.dist)
#Initial plot
fviz_pca_ind(Color_M12.PCA)
#Check Variance Explained by Components
summary(Color_M12.PCA)
Importance of components:
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
Standard deviation 2.6307486 1.2370753 0.35732936 0.255917262 0.155421527
Proportion of Variance 0.7953724 0.1758750 0.01467402 0.007526811 0.002776094
Cumulative Proportion 0.7953724 0.9712474 0.98592147 0.993448277 0.996224371
Comp.6 Comp.7 Comp.8 Comp.9
Standard deviation 0.114260728 0.0884077564 0.0516402054 0.0451547781
Proportion of Variance 0.001500396 0.0008982404 0.0003064699 0.0002343254
Cumulative Proportion 0.997724767 0.9986230073 0.9989294772 0.9991638026
Comp.10 Comp.11 Comp.12 Comp.13
Standard deviation 0.0373756136 0.0318318636 2.670671e-02 2.540062e-02
Proportion of Variance 0.0001605419 0.0001164491 8.196959e-05 7.414817e-05
Cumulative Proportion 0.9993243445 0.9994407936 9.995228e-01 9.995969e-01
Comp.14 Comp.15 Comp.16 Comp.17
Standard deviation 0.0230883094 2.010675e-02 1.808484e-02 1.604439e-02
Proportion of Variance 0.0000612627 4.646176e-05 3.758732e-05 2.958408e-05
Cumulative Proportion 0.9996581740 9.997046e-01 9.997422e-01 9.997718e-01
Comp.18 Comp.19 Comp.20 Comp.21
Standard deviation 0.0153445439 1.400353e-02 1.316914e-02 1.261185e-02
Proportion of Variance 0.0000270595 2.253653e-05 1.993088e-05 1.827973e-05
Cumulative Proportion 0.9997988667 9.998214e-01 9.998413e-01 9.998596e-01
Comp.22 Comp.23 Comp.24 Comp.25
Standard deviation 1.175780e-02 1.124303e-02 1.049205e-02 1.016488e-02
Proportion of Variance 1.588781e-05 1.452709e-05 1.265121e-05 1.187453e-05
Cumulative Proportion 9.998755e-01 9.998900e-01 9.999027e-01 9.999146e-01
Comp.26 Comp.27 Comp.28 Comp.29
Standard deviation 9.578818e-03 8.615514e-03 7.597832e-03 7.375186e-03
Proportion of Variance 1.054474e-05 8.530494e-06 6.634240e-06 6.251120e-06
Cumulative Proportion 9.999251e-01 9.999336e-01 9.999403e-01 9.999465e-01
Comp.30 Comp.31 Comp.32 Comp.33
Standard deviation 6.717477e-03 6.686356e-03 6.352131e-03 6.341865e-03
Proportion of Variance 5.185902e-06 5.137961e-06 4.637146e-06 4.622169e-06
Cumulative Proportion 9.999517e-01 9.999568e-01 9.999615e-01 9.999661e-01
Comp.34 Comp.35 Comp.36 Comp.37
Standard deviation 6.170623e-03 5.678885e-03 5.446104e-03 5.427442e-03
Proportion of Variance 4.375925e-06 3.706278e-06 3.408660e-06 3.385340e-06
Cumulative Proportion 9.999705e-01 9.999742e-01 9.999776e-01 9.999810e-01
Comp.38 Comp.39 Comp.40 Comp.41
Standard deviation 5.148174e-03 5.099105e-03 5.070893e-03 4.710738e-03
Proportion of Variance 3.045919e-06 2.988132e-06 2.955158e-06 2.550291e-06
Cumulative Proportion 9.999840e-01 9.999870e-01 9.999900e-01 9.999925e-01
Comp.42 Comp.43 Comp.44 Comp.45
Standard deviation 4.403416e-03 3.870200e-03 3.571450e-03 3.159518e-03
Proportion of Variance 2.228390e-06 1.721388e-06 1.465888e-06 1.147238e-06
Cumulative Proportion 9.999947e-01 9.999965e-01 9.999979e-01 9.999991e-01
Comp.46 Comp.47 Comp.48
Standard deviation 2.376894e-03 1.543709e-03 0
Proportion of Variance 6.492793e-07 2.738689e-07 0
Cumulative Proportion 9.999997e-01 1.000000e+00 1
#Visualize the importance of each principal component
fviz_eig(Color_M12.PCA, addlabels = TRUE)
PC1 Explains 79.5% of the variance in the color data.
#% Variance PCA 1
PC1_M12<-sprintf("%1.2f",0.7953724*100)
PC1_M12
[1] "79.54"
#% Variance PCA 2
PC2_M12<-sprintf("%1.2f",0.1758750*100)
PC2_M12
[1] "17.59"
#Prepare for Plotting
Color_M12.PCA_scores <- as.data.frame(Color_M12.PCA$scores[,c(1:2)])
Color_M12.PCA_scores$ID<-rownames(Color_M12.PCA_scores)
Color_M12.PCA_scores<-merge(Color_M12.PCA_scores, SampData)
#Plot PCA
Color_M12.PCA.plot<-ggplot(data = Color_M12.PCA_scores, aes(x = Comp.1, y = Comp.2)) +
geom_point(data = Color_M12.PCA_scores, aes(colour = Treatment), size = point.sz-1, alpha = 0.8) +
scale_colour_manual(values =HC.colors.o)+
theme_classic()+
scale_x_continuous(limits = c(-6, 12))+
scale_y_continuous(limits = c(-9, 9))+
labs(x=paste0('PC 1 (',PC1_M12,"%)"), y=paste0('PC 2 (',PC2_M12,"%)"))+
theme(axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="top");Color_M12.PCA.plot
Samples align along PC1 according to Treatment (Heated vs Control). Coordinates along PC1 will be extracted as the Color Score. Coordinates will multiplied by -1 for intuitive interpretation (Control > Heated) then made positive by adding 20
##Combine results from individual timepoints
ColorData.TP<-rbind(Color_W1.PCA_scores, Color_W2.PCA_scores,
Color_M1.PCA_scores, Color_M4.PCA_scores,
Color_M8.PCA_scores, Color_M12.PCA_scores)
##Retain PC1 as Color Score
ColorData.TP$Score_TP<-ColorData.TP$Comp.1
##Invert signs for Control > Heated for all except M4
ColorData.TP$Score_TP[-c(which(ColorData.TP$TimeP=="M4"))]<-ColorData.TP$Score_TP[-c(which(ColorData.TP$TimeP=="M4"))]*(-1)
#Adding 20 to make all score values positive
ColorData.TP$Score_TP<- ColorData.TP$Score_TP +20
##Initial Visual Check
ggplot(ColorData.TP, aes(x=Set, y=Score_TP)) +
geom_boxplot(alpha=0.5, shape=2, outlier.shape = NA)+
geom_jitter(shape=16, position=position_jitter(0.1))+
theme(axis.text.x = element_text(angle = 90))
##Plot by Treatment
ggplot(ColorData.TP, aes(x=Treatment, y=Score_TP)) +
geom_boxplot(alpha=0.5, shape=2, outlier.shape = NA)+
geom_jitter(shape=16, position=position_jitter(0.1))+
theme(axis.text.x = element_text(angle = 90))
##Merge with Color Data
names(ColorData.TP)
[1] "ID" "Comp.1" "Comp.2" "RandN" "TimeP" "Site"
[7] "Genotype" "Treat" "Treatment" "Vol_ml" "Wax.I_g" "Wax.F_g"
[13] "Set" "Score_TP"
ColorData<-merge(ColorData, ColorData.TP[,c(1,14)])
Repeat the calculation of Color Score for each Analysis Set. Initial: W1, W2, and M1 all from Aug 2022. Seasonal: M4 and M8 from Dec 2022 and Mar 2023. Annual: M12 from Aug 2023.
#Subset Initial Set
Color_IN<-subset(Color, AnSet=="Initial")
#Create matrix of standardized colors
Color_IN.mat <- as.matrix(cbind(Color_IN$Red.Norm.Coral,Color_IN$Green.Norm.Coral,Color_IN$Blue.Norm.Coral))
#Set row names to sample ID
rownames(Color_IN.mat) <- Color_IN$ID
#Create a Distance Matrix for PCA
Color_IN.dist <- vegdist(Color_IN.mat, method="euclidean", na.rm=TRUE)
#Run Principal Components Analysis
Color_IN.PCA <- princomp(Color_IN.dist)
#Initial plot
fviz_pca_ind(Color_IN.PCA)
#Check Variance Explained by Components
summary(Color_IN.PCA)
Importance of components:
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
Standard deviation 4.1826962 2.1657737 0.48586686 0.359847527 0.272587334
Proportion of Variance 0.7700304 0.2064531 0.01039034 0.005699441 0.003270443
Cumulative Proportion 0.7700304 0.9764835 0.98687385 0.992573288 0.995843731
Comp.6 Comp.7 Comp.8 Comp.9
Standard deviation 0.159242241 0.1446820580 0.107672222 0.0798730940
Proportion of Variance 0.001116122 0.0009213499 0.000510273 0.0002807995
Cumulative Proportion 0.996959854 0.9978812035 0.998391477 0.9986722760
Comp.10 Comp.11 Comp.12 Comp.13
Standard deviation 0.0715241421 0.0639132176 0.059260655 4.604625e-02
Proportion of Variance 0.0002251648 0.0001797946 0.000154571 9.332196e-05
Cumulative Proportion 0.9988974408 0.9990772354 0.999231806 9.993251e-01
Comp.14 Comp.15 Comp.16 Comp.17
Standard deviation 4.008741e-02 3.970686e-02 3.517360e-02 3.273128e-02
Proportion of Variance 7.073123e-05 6.939469e-05 5.445389e-05 4.715429e-05
Cumulative Proportion 9.993959e-01 9.994653e-01 9.995197e-01 9.995669e-01
Comp.18 Comp.19 Comp.20 Comp.21
Standard deviation 2.898735e-02 2.808120e-02 2.575963e-02 2.299958e-02
Proportion of Variance 3.698387e-05 3.470776e-05 2.920615e-05 2.328279e-05
Cumulative Proportion 9.996038e-01 9.996386e-01 9.996678e-01 9.996910e-01
Comp.22 Comp.23 Comp.24 Comp.25
Standard deviation 2.186291e-02 2.052701e-02 2.024329e-02 1.862487e-02
Proportion of Variance 2.103833e-05 1.854584e-05 1.803671e-05 1.526799e-05
Cumulative Proportion 9.997121e-01 9.997306e-01 9.997487e-01 9.997639e-01
Comp.26 Comp.27 Comp.28 Comp.29
Standard deviation 1.815918e-02 1.686596e-02 1.663200e-02 1.589272e-02
Proportion of Variance 1.451402e-05 1.252038e-05 1.217543e-05 1.111711e-05
Cumulative Proportion 9.997784e-01 9.997910e-01 9.998031e-01 9.998143e-01
Comp.30 Comp.31 Comp.32 Comp.33
Standard deviation 1.574270e-02 1.532020e-02 1.420221e-02 1.381501e-02
Proportion of Variance 1.090821e-05 1.033057e-05 8.877841e-06 8.400353e-06
Cumulative Proportion 9.998252e-01 9.998355e-01 9.998444e-01 9.998528e-01
Comp.34 Comp.35 Comp.36 Comp.37
Standard deviation 1.332151e-02 1.283564e-02 1.261680e-02 1.206079e-02
Proportion of Variance 7.810916e-06 7.251545e-06 7.006375e-06 6.402463e-06
Cumulative Proportion 9.998606e-01 9.998678e-01 9.998748e-01 9.998812e-01
Comp.38 Comp.39 Comp.40 Comp.41
Standard deviation 1.124497e-02 1.086078e-02 1.053526e-02 1.009382e-02
Proportion of Variance 5.565602e-06 5.191793e-06 4.885237e-06 4.484422e-06
Cumulative Proportion 9.998868e-01 9.998920e-01 9.998969e-01 9.999014e-01
Comp.42 Comp.43 Comp.44 Comp.45
Standard deviation 9.930423e-03 9.455409e-03 9.350470e-03 9.219234e-03
Proportion of Variance 4.340410e-06 3.935101e-06 3.848240e-06 3.740976e-06
Cumulative Proportion 9.999057e-01 9.999096e-01 9.999135e-01 9.999172e-01
Comp.46 Comp.47 Comp.48 Comp.49
Standard deviation 9.035607e-03 8.839414e-03 8.727809e-03 8.650300e-03
Proportion of Variance 3.593436e-06 3.439079e-06 3.352785e-06 3.293499e-06
Cumulative Proportion 9.999208e-01 9.999243e-01 9.999276e-01 9.999309e-01
Comp.50 Comp.51 Comp.52 Comp.53
Standard deviation 8.172662e-03 8.053628e-03 7.767203e-03 7.677681e-03
Proportion of Variance 2.939831e-06 2.854818e-06 2.655367e-06 2.594510e-06
Cumulative Proportion 9.999339e-01 9.999367e-01 9.999394e-01 9.999420e-01
Comp.54 Comp.55 Comp.56 Comp.57
Standard deviation 7.334958e-03 7.012964e-03 6.972150e-03 6.579010e-03
Proportion of Variance 2.368048e-06 2.164704e-06 2.139581e-06 1.905093e-06
Cumulative Proportion 9.999443e-01 9.999465e-01 9.999486e-01 9.999505e-01
Comp.58 Comp.59 Comp.60 Comp.61
Standard deviation 6.544438e-03 6.391438e-03 6.148349e-03 6.072563e-03
Proportion of Variance 1.885124e-06 1.798011e-06 1.663843e-06 1.623078e-06
Cumulative Proportion 9.999524e-01 9.999542e-01 9.999559e-01 9.999575e-01
Comp.62 Comp.63 Comp.64 Comp.65
Standard deviation 6.013432e-03 5.883451e-03 5.679406e-03 5.605064e-03
Proportion of Variance 1.591623e-06 1.523560e-06 1.419715e-06 1.382791e-06
Cumulative Proportion 9.999591e-01 9.999606e-01 9.999620e-01 9.999634e-01
Comp.66 Comp.67 Comp.68 Comp.69
Standard deviation 5.501061e-03 5.435311e-03 5.298509e-03 5.261887e-03
Proportion of Variance 1.331951e-06 1.300301e-06 1.235670e-06 1.218648e-06
Cumulative Proportion 9.999648e-01 9.999661e-01 9.999673e-01 9.999685e-01
Comp.70 Comp.71 Comp.72 Comp.73
Standard deviation 5.238756e-03 5.158565e-03 5.140607e-03 5.081688e-03
Proportion of Variance 1.207957e-06 1.171259e-06 1.163119e-06 1.136609e-06
Cumulative Proportion 9.999697e-01 9.999709e-01 9.999721e-01 9.999732e-01
Comp.74 Comp.75 Comp.76 Comp.77
Standard deviation 4.921165e-03 4.877300e-03 4.703063e-03 4.666744e-03
Proportion of Variance 1.065936e-06 1.047018e-06 9.735466e-07 9.585685e-07
Cumulative Proportion 9.999743e-01 9.999753e-01 9.999763e-01 9.999772e-01
Comp.78 Comp.79 Comp.80 Comp.81
Standard deviation 4.605739e-03 4.576412e-03 4.564210e-03 4.430193e-03
Proportion of Variance 9.336711e-07 9.218184e-07 9.169096e-07 8.638544e-07
Cumulative Proportion 9.999782e-01 9.999791e-01 9.999800e-01 9.999809e-01
Comp.82 Comp.83 Comp.84 Comp.85
Standard deviation 4.327573e-03 4.169650e-03 4.084059e-03 3.998648e-03
Proportion of Variance 8.242976e-07 7.652344e-07 7.341406e-07 7.037552e-07
Cumulative Proportion 9.999817e-01 9.999825e-01 9.999832e-01 9.999839e-01
Comp.86 Comp.87 Comp.88 Comp.89
Standard deviation 3.916605e-03 3.806960e-03 3.770586e-03 3.718579e-03
Proportion of Variance 6.751726e-07 6.378989e-07 6.257675e-07 6.086243e-07
Cumulative Proportion 9.999846e-01 9.999852e-01 9.999858e-01 9.999864e-01
Comp.90 Comp.91 Comp.92 Comp.93
Standard deviation 3.637183e-03 3.591003e-03 3.553504e-03 3.481705e-03
Proportion of Variance 5.822716e-07 5.675796e-07 5.557877e-07 5.335551e-07
Cumulative Proportion 9.999870e-01 9.999876e-01 9.999882e-01 9.999887e-01
Comp.94 Comp.95 Comp.96 Comp.97
Standard deviation 3.464752e-03 3.426086e-03 3.421553e-03 3.383552e-03
Proportion of Variance 5.283716e-07 5.166445e-07 5.152783e-07 5.038961e-07
Cumulative Proportion 9.999892e-01 9.999897e-01 9.999902e-01 9.999908e-01
Comp.98 Comp.99 Comp.100 Comp.101
Standard deviation 3.366876e-03 3.328492e-03 3.245798e-03 3.181874e-03
Proportion of Variance 4.989413e-07 4.876298e-07 4.637011e-07 4.456164e-07
Cumulative Proportion 9.999913e-01 9.999917e-01 9.999922e-01 9.999926e-01
Comp.102 Comp.103 Comp.104 Comp.105
Standard deviation 3.082356e-03 3.076179e-03 3.030577e-03 3.012694e-03
Proportion of Variance 4.181778e-07 4.165033e-07 4.042462e-07 3.994895e-07
Cumulative Proportion 9.999931e-01 9.999935e-01 9.999939e-01 9.999943e-01
Comp.106 Comp.107 Comp.108 Comp.109
Standard deviation 2.958537e-03 2.849973e-03 2.788687e-03 2.765204e-03
Proportion of Variance 3.852558e-07 3.575006e-07 3.422904e-07 3.365501e-07
Cumulative Proportion 9.999947e-01 9.999950e-01 9.999954e-01 9.999957e-01
Comp.110 Comp.111 Comp.112 Comp.113
Standard deviation 2.710038e-03 2.702422e-03 2.625591e-03 2.576072e-03
Proportion of Variance 3.232556e-07 3.214412e-07 3.034235e-07 2.920863e-07
Cumulative Proportion 9.999960e-01 9.999964e-01 9.999967e-01 9.999969e-01
Comp.114 Comp.115 Comp.116 Comp.117
Standard deviation 2.488275e-03 2.478443e-03 2.414752e-03 2.412794e-03
Proportion of Variance 2.725159e-07 2.703667e-07 2.566494e-07 2.562334e-07
Cumulative Proportion 9.999972e-01 9.999975e-01 9.999977e-01 9.999980e-01
Comp.118 Comp.119 Comp.120 Comp.121
Standard deviation 2.172755e-03 2.096889e-03 1.960744e-03 1.927494e-03
Proportion of Variance 2.077862e-07 1.935290e-07 1.692143e-07 1.635239e-07
Cumulative Proportion 9.999982e-01 9.999984e-01 9.999986e-01 9.999987e-01
Comp.122 Comp.123 Comp.124 Comp.125
Standard deviation 1.869706e-03 1.793586e-03 1.724265e-03 1.722076e-03
Proportion of Variance 1.538657e-07 1.415923e-07 1.308589e-07 1.305269e-07
Cumulative Proportion 9.999989e-01 9.999990e-01 9.999992e-01 9.999993e-01
Comp.126 Comp.127 Comp.128 Comp.129
Standard deviation 1.689744e-03 1.662524e-03 1.649268e-03 1.559736e-03
Proportion of Variance 1.256716e-07 1.216553e-07 1.197230e-07 1.070773e-07
Cumulative Proportion 9.999994e-01 9.999995e-01 9.999997e-01 9.999998e-01
Comp.130 Comp.131 Comp.132 Comp.133
Standard deviation 1.530742e-03 1.299190e-03 1.098459e-03 1.450001e-08
Proportion of Variance 1.031334e-07 7.429176e-08 5.310835e-08 9.254046e-18
Cumulative Proportion 9.999999e-01 9.999999e-01 1.000000e+00 1.000000e+00
#Visualize the importance of each principal component
fviz_eig(Color_IN.PCA, addlabels = TRUE)
PC1 Explains 77% of the variance in the color data.
#% Variance PCA 1
PC1_IN<-sprintf("%1.2f",0.7700304 *100)
PC1_IN
[1] "77.00"
#% Variance PCA 2
PC2_IN<-sprintf("%1.2f",0.2064531 *100)
PC2_IN
[1] "20.65"
#Prepare for Plotting
Color_IN.PCA_scores <- as.data.frame(Color_IN.PCA$scores[,c(1:2)])
Color_IN.PCA_scores$ID<-rownames(Color_IN.PCA_scores)
Color_IN.PCA_scores<-merge(Color_IN.PCA_scores, SampData)
#Plot PCA
Color_IN.PCA.plot<-ggplot(data = Color_IN.PCA_scores, aes(x = Comp.1, y = Comp.2)) +
geom_point(data = Color_IN.PCA_scores, aes(colour = Treatment), size = point.sz-1, alpha = 0.8) +
scale_colour_manual(values =HC.colors.o)+
theme_classic()+
scale_x_continuous(limits = c(-6, 12))+
scale_y_continuous(limits = c(-9, 9))+
labs(x=paste0('PC 1 (',PC1_IN,"%)"), y=paste0('PC 2 (',PC2_IN,"%)"))+
theme(axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="top");Color_IN.PCA.plot
Samples align along PC1 according to Treatment (Heated vs Control). Coordinates along PC1 will be extracted as the Color Score. Coordinates will multiplied by -1 for intuitive interpretation (Control > Heated) then made positive by adding 20
#Subset Seasonal Set
Color_SE<-subset(Color, AnSet=="Seasonal")
#Create matrix of standardized colors
Color_SE.mat <- as.matrix(cbind(Color_SE$Red.Norm.Coral,Color_SE$Green.Norm.Coral,Color_SE$Blue.Norm.Coral))
#Set row names to sample ID
rownames(Color_SE.mat) <- Color_SE$ID
#Create a Distance Matrix for PCA
Color_SE.dist <- vegdist(Color_SE.mat, method="euclidean", na.rm=TRUE)
#Run Principal Components Analysis
Color_SE.PCA <- princomp(Color_SE.dist)
#Initial plot
fviz_pca_ind(Color_SE.PCA)
#Check Variance Explained by Components
summary(Color_SE.PCA)
Importance of components:
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
Standard deviation 1.7831269 1.0944132 0.23601658 0.158286727 0.109855292
Proportion of Variance 0.7083081 0.2668212 0.01240917 0.005581446 0.002688436
Cumulative Proportion 0.7083081 0.9751293 0.98753848 0.993119927 0.995808363
Comp.6 Comp.7 Comp.8 Comp.9
Standard deviation 0.070421401 0.0595102457 0.0510308773 0.0378444968
Proportion of Variance 0.001104758 0.0007889349 0.0005801279 0.0003190533
Cumulative Proportion 0.996913121 0.9977020556 0.9982821836 0.9986012368
Comp.10 Comp.11 Comp.12 Comp.13
Standard deviation 0.0332508539 0.0273658172 0.0232401836 0.0219747848
Proportion of Variance 0.0002462994 0.0001668302 0.0001203197 0.0001075739
Cumulative Proportion 0.9988475362 0.9990143664 0.9991346861 0.9992422600
Comp.14 Comp.15 Comp.16 Comp.17
Standard deviation 2.079529e-02 1.761341e-02 1.712233e-02 1.634345e-02
Proportion of Variance 9.633578e-05 6.911059e-05 6.531056e-05 5.950388e-05
Cumulative Proportion 9.993386e-01 9.994077e-01 9.994730e-01 9.995325e-01
Comp.18 Comp.19 Comp.20 Comp.21
Standard deviation 1.333195e-02 1.325816e-02 1.269150e-02 0.0112544501
Proportion of Variance 3.959544e-05 3.915835e-05 3.588256e-05 0.0000282167
Cumulative Proportion 9.995721e-01 9.996113e-01 9.996472e-01 0.9996753739
Comp.22 Comp.23 Comp.24 Comp.25
Standard deviation 1.094100e-02 9.783721e-03 0.0090568507 8.625282e-03
Proportion of Variance 2.666684e-05 2.132386e-05 0.0000182731 1.657312e-05
Cumulative Proportion 9.997020e-01 9.997234e-01 0.9997416376 9.997582e-01
Comp.26 Comp.27 Comp.28 Comp.29
Standard deviation 8.158747e-03 7.940254e-03 7.697729e-03 7.481304e-03
Proportion of Variance 1.482875e-05 1.404515e-05 1.320028e-05 1.246845e-05
Cumulative Proportion 9.997730e-01 9.997871e-01 9.998003e-01 9.998128e-01
Comp.30 Comp.31 Comp.32 Comp.33
Standard deviation 7.157935e-03 7.053127e-03 6.784967e-03 6.448160e-03
Proportion of Variance 1.141388e-05 1.108207e-05 1.025541e-05 9.262524e-06
Cumulative Proportion 9.998242e-01 9.998352e-01 9.998455e-01 9.998548e-01
Comp.34 Comp.35 Comp.36 Comp.37
Standard deviation 6.148759e-03 5.901965e-03 5.509151e-03 5.296267e-03
Proportion of Variance 8.422338e-06 7.759808e-06 6.761250e-06 6.248811e-06
Cumulative Proportion 9.998632e-01 9.998709e-01 9.998777e-01 9.998840e-01
Comp.38 Comp.39 Comp.40 Comp.41
Standard deviation 5.191312e-03 5.068710e-03 4.909169e-03 4.794832e-03
Proportion of Variance 6.003603e-06 5.723379e-06 5.368755e-06 5.121587e-06
Cumulative Proportion 9.998900e-01 9.998957e-01 9.999011e-01 9.999062e-01
Comp.42 Comp.43 Comp.44 Comp.45
Standard deviation 4.724916e-03 4.589354e-03 4.534700e-03 4.480022e-03
Proportion of Variance 4.973315e-06 4.692031e-06 4.580943e-06 4.471137e-06
Cumulative Proportion 9.999112e-01 9.999158e-01 9.999204e-01 9.999249e-01
Comp.46 Comp.47 Comp.48 Comp.49
Standard deviation 4.284972e-03 4.018862e-03 3.792015e-03 3.764522e-03
Proportion of Variance 4.090286e-06 3.598023e-06 3.203301e-06 3.157020e-06
Cumulative Proportion 9.999290e-01 9.999326e-01 9.999358e-01 9.999389e-01
Comp.50 Comp.51 Comp.52 Comp.53
Standard deviation 3.715825e-03 3.637332e-03 3.554652e-03 3.460813e-03
Proportion of Variance 3.075872e-06 2.947295e-06 2.814828e-06 2.668173e-06
Cumulative Proportion 9.999420e-01 9.999450e-01 9.999478e-01 9.999504e-01
Comp.54 Comp.55 Comp.56 Comp.57
Standard deviation 3.347437e-03 3.220543e-03 3.190222e-03 3.171177e-03
Proportion of Variance 2.496217e-06 2.310553e-06 2.267251e-06 2.240261e-06
Cumulative Proportion 9.999529e-01 9.999553e-01 9.999575e-01 9.999598e-01
Comp.58 Comp.59 Comp.60 Comp.61
Standard deviation 3.141223e-03 3.087500e-03 3.017919e-03 2.948389e-03
Proportion of Variance 2.198140e-06 2.123595e-06 2.028956e-06 1.936544e-06
Cumulative Proportion 9.999620e-01 9.999641e-01 9.999661e-01 9.999681e-01
Comp.62 Comp.63 Comp.64 Comp.65
Standard deviation 2.917200e-03 2.843875e-03 2.770194e-03 2.707911e-03
Proportion of Variance 1.895790e-06 1.801685e-06 1.709535e-06 1.633528e-06
Cumulative Proportion 9.999699e-01 9.999717e-01 9.999735e-01 9.999751e-01
Comp.66 Comp.67 Comp.68 Comp.69
Standard deviation 2.679583e-03 2.619747e-03 2.598994e-03 2.559106e-03
Proportion of Variance 1.599529e-06 1.528890e-06 1.504764e-06 1.458930e-06
Cumulative Proportion 9.999767e-01 9.999782e-01 9.999797e-01 9.999812e-01
Comp.70 Comp.71 Comp.72 Comp.73
Standard deviation 2.499851e-03 2.470944e-03 2.465089e-03 2.448198e-03
Proportion of Variance 1.392150e-06 1.360139e-06 1.353701e-06 1.335213e-06
Cumulative Proportion 9.999826e-01 9.999839e-01 9.999853e-01 9.999866e-01
Comp.74 Comp.75 Comp.76 Comp.77
Standard deviation 2.360869e-03 2.321919e-03 2.212598e-03 2.182403e-03
Proportion of Variance 1.241656e-06 1.201024e-06 1.090593e-06 1.061030e-06
Cumulative Proportion 9.999879e-01 9.999891e-01 9.999902e-01 9.999912e-01
Comp.78 Comp.79 Comp.80 Comp.81
Standard deviation 2.091460e-03 2.043928e-03 1.953462e-03 1.929549e-03
Proportion of Variance 9.744440e-07 9.306552e-07 8.500954e-07 8.294097e-07
Cumulative Proportion 9.999922e-01 9.999931e-01 9.999940e-01 9.999948e-01
Comp.82 Comp.83 Comp.84 Comp.85
Standard deviation 1.844990e-03 1.778297e-03 1.673213e-03 1.537657e-03
Proportion of Variance 7.583084e-07 7.044760e-07 6.236773e-07 5.267163e-07
Cumulative Proportion 9.999956e-01 9.999963e-01 9.999969e-01 9.999974e-01
Comp.86 Comp.87 Comp.88 Comp.89
Standard deviation 1.483148e-03 1.374735e-03 1.340049e-03 1.152068e-03
Proportion of Variance 4.900345e-07 4.210132e-07 4.000363e-07 2.956743e-07
Cumulative Proportion 9.999979e-01 9.999983e-01 9.999987e-01 9.999990e-01
Comp.90 Comp.91 Comp.92 Comp.93
Standard deviation 1.074884e-03 9.947533e-04 9.217579e-04 8.529013e-04
Proportion of Variance 2.573837e-07 2.204390e-07 1.892742e-07 1.620523e-07
Cumulative Proportion 9.999993e-01 9.999995e-01 9.999997e-01 9.999999e-01
Comp.94 Comp.95 Comp.96
Standard deviation 5.806749e-04 5.703946e-04 8.811875e-09
Proportion of Variance 7.511451e-08 7.247838e-08 1.729794e-17
Cumulative Proportion 9.999999e-01 1.000000e+00 1.000000e+00
#Visualize the importance of each principal component
fviz_eig(Color_SE.PCA, addlabels = TRUE)
PC1 Explains 70.8% of the variance in the color data.
#% Variance PCA 1
PC1_SE<-sprintf("%1.2f",0.7083081 *100)
PC1_SE
[1] "70.83"
#% Variance PCA 2
PC2_SE<-sprintf("%1.2f",0.2668212 *100)
PC2_SE
[1] "26.68"
#Prepare for Plotting
Color_SE.PCA_scores <- as.data.frame(Color_SE.PCA$scores[,c(1:2)])
Color_SE.PCA_scores$ID<-rownames(Color_SE.PCA_scores)
Color_SE.PCA_scores<-merge(Color_SE.PCA_scores, SampData)
#Plot PCA
Color_SE.PCA.plot<-ggplot(data = Color_SE.PCA_scores, aes(x = Comp.1, y = Comp.2)) +
geom_point(data = Color_SE.PCA_scores, aes(colour = Treatment), size = point.sz-1, alpha = 0.8) +
scale_colour_manual(values =HC.colors.o)+
theme_classic()+
scale_x_continuous(limits = c(-6, 12))+
scale_y_continuous(limits = c(-9, 9))+
labs(x=paste0('PC 1 (',PC1_SE,"%)"), y=paste0('PC 2 (',PC2_SE,"%)"))+
theme(axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="top");Color_SE.PCA.plot
Samples align along PC1 according to Treatment, but less split between Heated vs Control. Coordinates along PC1 will be extracted as the Color Score. *Note: These coordinates should not be multiplied by -1 for intuitive interpretation (Control > Heated), but will still be made positive by adding 20
#Subset Annual Set
Color_AN<-subset(Color, AnSet=="Annual")
#Create matrix of standardized colors
Color_AN.mat <- as.matrix(cbind(Color_AN$Red.Norm.Coral,Color_AN$Green.Norm.Coral,Color_AN$Blue.Norm.Coral))
#Set row names to sample ID
rownames(Color_AN.mat) <- Color_AN$ID
#Create a Distance Matrix for PCA
Color_AN.dist <- vegdist(Color_AN.mat, method="euclidean", na.rm=TRUE)
#Run Principal Components Analysis
Color_AN.PCA <- princomp(Color_AN.dist)
#Initial plot
fviz_pca_ind(Color_AN.PCA)
#Check Variance Explained by Components
summary(Color_AN.PCA)
Importance of components:
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
Standard deviation 2.6307486 1.2370753 0.35732936 0.255917262 0.155421527
Proportion of Variance 0.7953724 0.1758750 0.01467402 0.007526811 0.002776094
Cumulative Proportion 0.7953724 0.9712474 0.98592147 0.993448277 0.996224371
Comp.6 Comp.7 Comp.8 Comp.9
Standard deviation 0.114260728 0.0884077564 0.0516402054 0.0451547781
Proportion of Variance 0.001500396 0.0008982404 0.0003064699 0.0002343254
Cumulative Proportion 0.997724767 0.9986230073 0.9989294772 0.9991638026
Comp.10 Comp.11 Comp.12 Comp.13
Standard deviation 0.0373756136 0.0318318636 2.670671e-02 2.540062e-02
Proportion of Variance 0.0001605419 0.0001164491 8.196959e-05 7.414817e-05
Cumulative Proportion 0.9993243445 0.9994407936 9.995228e-01 9.995969e-01
Comp.14 Comp.15 Comp.16 Comp.17
Standard deviation 0.0230883094 2.010675e-02 1.808484e-02 1.604439e-02
Proportion of Variance 0.0000612627 4.646176e-05 3.758732e-05 2.958408e-05
Cumulative Proportion 0.9996581740 9.997046e-01 9.997422e-01 9.997718e-01
Comp.18 Comp.19 Comp.20 Comp.21
Standard deviation 0.0153445439 1.400353e-02 1.316914e-02 1.261185e-02
Proportion of Variance 0.0000270595 2.253653e-05 1.993088e-05 1.827973e-05
Cumulative Proportion 0.9997988667 9.998214e-01 9.998413e-01 9.998596e-01
Comp.22 Comp.23 Comp.24 Comp.25
Standard deviation 1.175780e-02 1.124303e-02 1.049205e-02 1.016488e-02
Proportion of Variance 1.588781e-05 1.452709e-05 1.265121e-05 1.187453e-05
Cumulative Proportion 9.998755e-01 9.998900e-01 9.999027e-01 9.999146e-01
Comp.26 Comp.27 Comp.28 Comp.29
Standard deviation 9.578818e-03 8.615514e-03 7.597832e-03 7.375186e-03
Proportion of Variance 1.054474e-05 8.530494e-06 6.634240e-06 6.251120e-06
Cumulative Proportion 9.999251e-01 9.999336e-01 9.999403e-01 9.999465e-01
Comp.30 Comp.31 Comp.32 Comp.33
Standard deviation 6.717477e-03 6.686356e-03 6.352131e-03 6.341865e-03
Proportion of Variance 5.185902e-06 5.137961e-06 4.637146e-06 4.622169e-06
Cumulative Proportion 9.999517e-01 9.999568e-01 9.999615e-01 9.999661e-01
Comp.34 Comp.35 Comp.36 Comp.37
Standard deviation 6.170623e-03 5.678885e-03 5.446104e-03 5.427442e-03
Proportion of Variance 4.375925e-06 3.706278e-06 3.408660e-06 3.385340e-06
Cumulative Proportion 9.999705e-01 9.999742e-01 9.999776e-01 9.999810e-01
Comp.38 Comp.39 Comp.40 Comp.41
Standard deviation 5.148174e-03 5.099105e-03 5.070893e-03 4.710738e-03
Proportion of Variance 3.045919e-06 2.988132e-06 2.955158e-06 2.550291e-06
Cumulative Proportion 9.999840e-01 9.999870e-01 9.999900e-01 9.999925e-01
Comp.42 Comp.43 Comp.44 Comp.45
Standard deviation 4.403416e-03 3.870200e-03 3.571450e-03 3.159518e-03
Proportion of Variance 2.228390e-06 1.721388e-06 1.465888e-06 1.147238e-06
Cumulative Proportion 9.999947e-01 9.999965e-01 9.999979e-01 9.999991e-01
Comp.46 Comp.47 Comp.48
Standard deviation 2.376894e-03 1.543709e-03 0
Proportion of Variance 6.492793e-07 2.738689e-07 0
Cumulative Proportion 9.999997e-01 1.000000e+00 1
#Visualize the importance of each principal component
fviz_eig(Color_AN.PCA, addlabels = TRUE)
PC1 Explains 79.5% of the variance in the color data.
#% Variance PCA 1
PC1_AN<-sprintf("%1.2f",0.7953724 *100)
PC1_AN
[1] "79.54"
#% Variance PCA 2
PC2_AN<-sprintf("%1.2f",0.1758750 *100)
PC2_AN
[1] "17.59"
#Prepare for Plotting
Color_AN.PCA_scores <- as.data.frame(Color_AN.PCA$scores[,c(1:2)])
Color_AN.PCA_scores$ID<-rownames(Color_AN.PCA_scores)
Color_AN.PCA_scores<-merge(Color_AN.PCA_scores, SampData)
#Plot PCA
Color_AN.PCA.plot<-ggplot(data = Color_AN.PCA_scores, aes(x = Comp.1, y = Comp.2)) +
geom_point(data = Color_AN.PCA_scores, aes(colour = Treatment), size = point.sz-1, alpha = 0.8) +
scale_colour_manual(values =HC.colors.o)+
theme_classic()+
scale_x_continuous(limits = c(-6, 12))+
scale_y_continuous(limits = c(-9, 9))+
labs(x=paste0('PC 1 (',PC1_AN,"%)"), y=paste0('PC 2 (',PC2_AN,"%)"))+
theme(axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="top");Color_AN.PCA.plot
Samples align along PC1 according to Treatment (Heated vs Control). Coordinates along PC1 will be extracted as the Color Score. Coordinates will multiplied by -1 for intuitive interpretation (Control > Heated) then made positive by adding 20
##Combine results from individual timepoints
ColorData.Set<-rbind(Color_IN.PCA_scores, Color_SE.PCA_scores,
Color_AN.PCA_scores)
##Retain PC1 as Color Score
ColorData.Set$Score_Set<-ColorData.Set$Comp.1
##Add an Analysis Set Variable
ColorData.Set$AnSet<-"Initial"
ColorData.Set$AnSet[which(ColorData.Set$TimeP=="M4" | ColorData.Set$TimeP== "M8")]<-"Seasonal"
ColorData.Set$AnSet[which(ColorData.Set$TimeP=="M12")]<-"Annual"
##Invert signs for Control > Heated for all except Seasonal
ColorData.Set$Score_Set[-c(which(ColorData.Set$AnSet=="Seasonal"))]<-ColorData.Set$Score_Set[-c(which(ColorData.Set$AnSet=="Seasonal"))]*(-1)
#Adding 20 to make all score values positive
ColorData.Set$Score_Set<- ColorData.Set$Score_Set +20
##Initial Visual Check
ggplot(ColorData.Set, aes(x=Set, y=Score_Set)) +
geom_boxplot(alpha=0.5, shape=2, outlier.shape = NA)+
geom_jitter(shape=16, position=position_jitter(0.1))+
theme(axis.text.x = element_text(angle = 90))
##Plot by Treatment
ggplot(ColorData.Set, aes(x=Treatment, y=Score_Set)) +
geom_boxplot(alpha=0.5, shape=2, outlier.shape = NA)+
geom_jitter(shape=16, position=position_jitter(0.1))+
theme(axis.text.x = element_text(angle = 90))
##Merge with Color Data
names(ColorData.Set)
[1] "ID" "Comp.1" "Comp.2" "RandN" "TimeP" "Site"
[7] "Genotype" "Treat" "Treatment" "Vol_ml" "Wax.I_g" "Wax.F_g"
[13] "Set" "Score_Set" "AnSet"
ColorData<-merge(ColorData, ColorData.Set[,c(1,14)])
Repeat the calculation of Color Score for each Season. Summer: W1, W2, and M1 from Aug 2022 plus M12 from Aug 2023. Winter: M4 from Dec 2022. Spring: M8 from Mar 2023.
#Subset Summer Set
Color_SU<-subset(Color, Season=="Summer")
#Create matrix of standardized colors
Color_SU.mat <- as.matrix(cbind(Color_SU$Red.Norm.Coral,Color_SU$Green.Norm.Coral,Color_SU$Blue.Norm.Coral))
#Set row names to sample ID
rownames(Color_SU.mat) <- Color_SU$ID
#Create a Distance Matrix for PCA
Color_SU.dist <- vegdist(Color_SU.mat, method="euclidean", na.rm=TRUE)
#Run Principal Components Analysis
Color_SU.PCA <- princomp(Color_SU.dist)
#Initial plot
fviz_pca_ind(Color_SU.PCA)
#Check Variance Explained by Components
summary(Color_SU.PCA)
Importance of components:
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
Standard deviation 4.8915583 2.5331620 0.58144919 0.43952451 0.264126621
Proportion of Variance 0.7699187 0.2064792 0.01087862 0.00621608 0.002244785
Cumulative Proportion 0.7699187 0.9763979 0.98727651 0.99349259 0.995737379
Comp.6 Comp.7 Comp.8 Comp.9
Standard deviation 0.196631060 0.1709796771 0.1182729362 0.1015137033
Proportion of Variance 0.001244098 0.0009406745 0.0004501126 0.0003315887
Cumulative Proportion 0.996981477 0.9979221516 0.9983722642 0.9987038529
Comp.10 Comp.11 Comp.12 Comp.13
Standard deviation 0.0781748741 0.0763796129 0.0677732365 0.0570422849
Proportion of Variance 0.0001966458 0.0001877177 0.0001477974 0.0001046994
Cumulative Proportion 0.9989004987 0.9990882165 0.9992360139 0.9993407133
Comp.14 Comp.15 Comp.16 Comp.17
Standard deviation 5.394553e-02 4.902570e-02 4.079330e-02 3.584349e-02
Proportion of Variance 9.363998e-05 7.733891e-05 5.354613e-05 4.134004e-05
Cumulative Proportion 9.994344e-01 9.995117e-01 9.995652e-01 9.996066e-01
Comp.18 Comp.19 Comp.20 Comp.21
Standard deviation 3.340871e-02 0.0301076889 2.933657e-02 2.711947e-02
Proportion of Variance 3.591451e-05 0.0000291679 2.769294e-05 2.366535e-05
Cumulative Proportion 9.996425e-01 0.9996716608 9.996994e-01 9.997230e-01
Comp.22 Comp.23 Comp.24 Comp.25
Standard deviation 2.566462e-02 2.417347e-02 2.269387e-02 2.101489e-02
Proportion of Variance 2.119435e-05 1.880305e-05 1.657171e-05 1.421034e-05
Cumulative Proportion 9.997442e-01 9.997630e-01 9.997796e-01 9.997938e-01
Comp.26 Comp.27 Comp.28 Comp.29
Standard deviation 0.0197659817 1.938922e-02 1.830301e-02 1.691773e-02
Proportion of Variance 0.0000125715 1.209682e-05 1.077942e-05 9.209474e-06
Cumulative Proportion 0.9998063700 9.998185e-01 9.998292e-01 9.998385e-01
Comp.30 Comp.31 Comp.32 Comp.33
Standard deviation 1.651537e-02 1.601172e-02 1.542648e-02 1.499796e-02
Proportion of Variance 8.776616e-06 8.249474e-06 7.657451e-06 7.237934e-06
Cumulative Proportion 9.998472e-01 9.998555e-01 9.998631e-01 9.998704e-01
Comp.34 Comp.35 Comp.36 Comp.37
Standard deviation 1.443250e-02 1.381923e-02 1.342281e-02 1.217527e-02
Proportion of Variance 6.702449e-06 6.144949e-06 5.797454e-06 4.769884e-06
Cumulative Proportion 9.998771e-01 9.998832e-01 9.998890e-01 9.998938e-01
Comp.38 Comp.39 Comp.40 Comp.41
Standard deviation 1.173751e-02 1.165155e-02 1.151573e-02 1.102541e-02
Proportion of Variance 4.433044e-06 4.368353e-06 4.267109e-06 3.911468e-06
Cumulative Proportion 9.998982e-01 9.999026e-01 9.999069e-01 9.999108e-01
Comp.42 Comp.43 Comp.44 Comp.45
Standard deviation 1.053519e-02 1.043742e-02 1.024650e-02 1.001860e-02
Proportion of Variance 3.571375e-06 3.505395e-06 3.378326e-06 3.229718e-06
Cumulative Proportion 9.999143e-01 9.999178e-01 9.999212e-01 9.999245e-01
Comp.46 Comp.47 Comp.48 Comp.49
Standard deviation 9.733882e-03 9.484444e-03 9.274579e-03 9.048981e-03
Proportion of Variance 3.048755e-06 2.894504e-06 2.767826e-06 2.634813e-06
Cumulative Proportion 9.999275e-01 9.999304e-01 9.999332e-01 9.999358e-01
Comp.50 Comp.51 Comp.52 Comp.53
Standard deviation 8.706959e-03 8.322465e-03 8.225174e-03 8.067931e-03
Proportion of Variance 2.439402e-06 2.228714e-06 2.176910e-06 2.094473e-06
Cumulative Proportion 9.999382e-01 9.999405e-01 9.999426e-01 9.999447e-01
Comp.54 Comp.55 Comp.56 Comp.57
Standard deviation 7.727035e-03 7.640141e-03 7.600167e-03 7.358393e-03
Proportion of Variance 1.921216e-06 1.878249e-06 1.858646e-06 1.742274e-06
Cumulative Proportion 9.999467e-01 9.999485e-01 9.999504e-01 9.999521e-01
Comp.58 Comp.59 Comp.60 Comp.61
Standard deviation 7.041795e-03 6.667268e-03 6.646761e-03 6.430422e-03
Proportion of Variance 1.595575e-06 1.430363e-06 1.421577e-06 1.330544e-06
Cumulative Proportion 9.999537e-01 9.999552e-01 9.999566e-01 9.999579e-01
Comp.62 Comp.63 Comp.64 Comp.65
Standard deviation 6.160445e-03 6.048996e-03 5.960336e-03 5.918472e-03
Proportion of Variance 1.221166e-06 1.177381e-06 1.143120e-06 1.127118e-06
Cumulative Proportion 9.999591e-01 9.999603e-01 9.999615e-01 9.999626e-01
Comp.66 Comp.67 Comp.68 Comp.69
Standard deviation 5.768823e-03 5.642129e-03 5.592999e-03 5.536619e-03
Proportion of Variance 1.070840e-06 1.024322e-06 1.006560e-06 9.863697e-07
Cumulative Proportion 9.999637e-01 9.999647e-01 9.999657e-01 9.999667e-01
Comp.70 Comp.71 Comp.72 Comp.73
Standard deviation 5.408631e-03 5.278131e-03 5.234859e-03 5.063060e-03
Proportion of Variance 9.412937e-07 8.964183e-07 8.817802e-07 8.248529e-07
Cumulative Proportion 9.999676e-01 9.999685e-01 9.999694e-01 9.999702e-01
Comp.74 Comp.75 Comp.76 Comp.77
Standard deviation 5.011592e-03 4.926231e-03 4.911640e-03 4.866279e-03
Proportion of Variance 8.081682e-07 7.808723e-07 7.762532e-07 7.619813e-07
Cumulative Proportion 9.999710e-01 9.999718e-01 9.999726e-01 9.999733e-01
Comp.78 Comp.79 Comp.80 Comp.81
Standard deviation 4.760604e-03 4.738263e-03 4.683397e-03 4.598794e-03
Proportion of Variance 7.292468e-07 7.224182e-07 7.057848e-07 6.805160e-07
Cumulative Proportion 9.999741e-01 9.999748e-01 9.999755e-01 9.999762e-01
Comp.82 Comp.83 Comp.84 Comp.85
Standard deviation 4.516136e-03 4.489048e-03 4.414349e-03 4.395698e-03
Proportion of Variance 6.562728e-07 6.484238e-07 6.270235e-07 6.217362e-07
Cumulative Proportion 9.999768e-01 9.999775e-01 9.999781e-01 9.999787e-01
Comp.86 Comp.87 Comp.88 Comp.89
Standard deviation 4.382661e-03 4.313718e-03 4.248274e-03 4.194347e-03
Proportion of Variance 6.180536e-07 5.987617e-07 5.807316e-07 5.660817e-07
Cumulative Proportion 9.999794e-01 9.999800e-01 9.999805e-01 9.999811e-01
Comp.90 Comp.91 Comp.92 Comp.93
Standard deviation 4.164089e-03 4.137535e-03 4.054804e-03 4.030350e-03
Proportion of Variance 5.579437e-07 5.508504e-07 5.290418e-07 5.226800e-07
Cumulative Proportion 9.999817e-01 9.999822e-01 9.999827e-01 9.999833e-01
Comp.94 Comp.95 Comp.96 Comp.97
Standard deviation 3.972372e-03 3.945312e-03 3.829803e-03 3.811305e-03
Proportion of Variance 5.077503e-07 5.008562e-07 4.719580e-07 4.674098e-07
Cumulative Proportion 9.999838e-01 9.999843e-01 9.999847e-01 9.999852e-01
Comp.98 Comp.99 Comp.100 Comp.101
Standard deviation 3.772533e-03 3.524232e-03 3.491178e-03 3.421693e-03
Proportion of Variance 4.579484e-07 3.996495e-07 3.921881e-07 3.767319e-07
Cumulative Proportion 9.999857e-01 9.999861e-01 9.999865e-01 9.999868e-01
Comp.102 Comp.103 Comp.104 Comp.105
Standard deviation 3.409835e-03 3.395956e-03 3.318040e-03 3.289384e-03
Proportion of Variance 3.741253e-07 3.710860e-07 3.542532e-07 3.481606e-07
Cumulative Proportion 9.999872e-01 9.999876e-01 9.999879e-01 9.999883e-01
Comp.106 Comp.107 Comp.108 Comp.109
Standard deviation 3.267900e-03 3.255476e-03 3.228306e-03 3.181721e-03
Proportion of Variance 3.436276e-07 3.410196e-07 3.353512e-07 3.257427e-07
Cumulative Proportion 9.999886e-01 9.999890e-01 9.999893e-01 9.999896e-01
Comp.110 Comp.111 Comp.112 Comp.113
Standard deviation 3.161413e-03 3.084246e-03 3.079741e-03 3.074371e-03
Proportion of Variance 3.215977e-07 3.060894e-07 3.051960e-07 3.041327e-07
Cumulative Proportion 9.999900e-01 9.999903e-01 9.999906e-01 9.999909e-01
Comp.114 Comp.115 Comp.116 Comp.117
Standard deviation 2.994603e-03 2.980454e-03 2.940033e-03 2.928299e-03
Proportion of Variance 2.885552e-07 2.858348e-07 2.781345e-07 2.759187e-07
Cumulative Proportion 9.999912e-01 9.999914e-01 9.999917e-01 9.999920e-01
Comp.118 Comp.119 Comp.120 Comp.121
Standard deviation 2.861354e-03 2.855350e-03 2.795740e-03 2.757646e-03
Proportion of Variance 2.634472e-07 2.623427e-07 2.515034e-07 2.446963e-07
Cumulative Proportion 9.999923e-01 9.999925e-01 9.999928e-01 9.999930e-01
Comp.122 Comp.123 Comp.124 Comp.125
Standard deviation 2.721554e-03 2.718007e-03 2.684701e-03 2.671416e-03
Proportion of Variance 2.383331e-07 2.377123e-07 2.319221e-07 2.296326e-07
Cumulative Proportion 9.999933e-01 9.999935e-01 9.999937e-01 9.999940e-01
Comp.126 Comp.127 Comp.128 Comp.129
Standard deviation 2.615013e-03 2.559642e-03 2.552890e-03 2.477776e-03
Proportion of Variance 2.200382e-07 2.108185e-07 2.097077e-07 1.975489e-07
Cumulative Proportion 9.999942e-01 9.999944e-01 9.999946e-01 9.999948e-01
Comp.130 Comp.131 Comp.132 Comp.133
Standard deviation 2.459162e-03 2.455953e-03 2.408848e-03 2.407398e-03
Proportion of Variance 1.945919e-07 1.940843e-07 1.867106e-07 1.864860e-07
Cumulative Proportion 9.999950e-01 9.999952e-01 9.999954e-01 9.999956e-01
Comp.134 Comp.135 Comp.136 Comp.137
Standard deviation 2.340052e-03 2.307746e-03 2.301377e-03 2.296209e-03
Proportion of Variance 1.761982e-07 1.713667e-07 1.704221e-07 1.696575e-07
Cumulative Proportion 9.999957e-01 9.999959e-01 9.999961e-01 9.999962e-01
Comp.138 Comp.139 Comp.140 Comp.141
Standard deviation 2.261618e-03 2.240437e-03 2.213104e-03 2.210734e-03
Proportion of Variance 1.645845e-07 1.615161e-07 1.575992e-07 1.572618e-07
Cumulative Proportion 9.999964e-01 9.999966e-01 9.999967e-01 9.999969e-01
Comp.142 Comp.143 Comp.144 Comp.145
Standard deviation 2.166795e-03 2.135584e-03 2.110592e-03 2.087620e-03
Proportion of Variance 1.510727e-07 1.467519e-07 1.433372e-07 1.402341e-07
Cumulative Proportion 9.999970e-01 9.999972e-01 9.999973e-01 9.999975e-01
Comp.146 Comp.147 Comp.148 Comp.149
Standard deviation 2.038759e-03 2.016575e-03 2.012446e-03 1.988920e-03
Proportion of Variance 1.337464e-07 1.308516e-07 1.303164e-07 1.272873e-07
Cumulative Proportion 9.999976e-01 9.999977e-01 9.999979e-01 9.999980e-01
Comp.150 Comp.151 Comp.152 Comp.153
Standard deviation 1.984969e-03 1.962661e-03 1.918415e-03 1.759514e-03
Proportion of Variance 1.267821e-07 1.239484e-07 1.184228e-07 9.961750e-08
Cumulative Proportion 9.999981e-01 9.999982e-01 9.999984e-01 9.999985e-01
Comp.154 Comp.155 Comp.156 Comp.157
Standard deviation 1.751617e-03 1.668932e-03 1.652206e-03 1.628488e-03
Proportion of Variance 9.872537e-08 8.962464e-08 8.783730e-08 8.533353e-08
Cumulative Proportion 9.999986e-01 9.999986e-01 9.999987e-01 9.999988e-01
Comp.158 Comp.159 Comp.160 Comp.161
Standard deviation 1.615044e-03 1.507085e-03 1.497130e-03 1.461142e-03
Proportion of Variance 8.393041e-08 7.308462e-08 7.212231e-08 6.869660e-08
Cumulative Proportion 9.999989e-01 9.999990e-01 9.999990e-01 9.999991e-01
Comp.162 Comp.163 Comp.164 Comp.165
Standard deviation 1.446359e-03 1.414114e-03 1.387981e-03 1.375334e-03
Proportion of Variance 6.731360e-08 6.434568e-08 6.198937e-08 6.086490e-08
Cumulative Proportion 9.999992e-01 9.999992e-01 9.999993e-01 9.999994e-01
Comp.166 Comp.167 Comp.168 Comp.169
Standard deviation 1.340003e-03 1.339709e-03 1.331433e-03 1.290526e-03
Proportion of Variance 5.777791e-08 5.775258e-08 5.704125e-08 5.358998e-08
Cumulative Proportion 9.999994e-01 9.999995e-01 9.999995e-01 9.999996e-01
Comp.170 Comp.171 Comp.172 Comp.173
Standard deviation 1.247973e-03 1.216443e-03 1.204189e-03 1.174165e-03
Proportion of Variance 5.011418e-08 4.761393e-08 4.665942e-08 4.436176e-08
Cumulative Proportion 9.999996e-01 9.999997e-01 9.999997e-01 9.999998e-01
Comp.174 Comp.175 Comp.176 Comp.177
Standard deviation 1.134842e-03 1.106004e-03 1.054603e-03 1.025443e-03
Proportion of Variance 4.144017e-08 3.936080e-08 3.578723e-08 3.383558e-08
Cumulative Proportion 9.999998e-01 9.999999e-01 9.999999e-01 9.999999e-01
Comp.178 Comp.179 Comp.180 Comp.181
Standard deviation 9.382422e-04 8.447040e-04 5.853120e-04 0
Proportion of Variance 2.832568e-08 2.295934e-08 1.102364e-08 0
Cumulative Proportion 1.000000e+00 1.000000e+00 1.000000e+00 1
#Visualize the importance of each principal component
fviz_eig(Color_SU.PCA, addlabels = TRUE)
PC1 Explains 77% of the variance in the color data.
#% Variance PCA 1
PC1_SU<-sprintf("%1.2f",0.7699187 *100)
PC1_SU
[1] "76.99"
#% Variance PCA 2
PC2_SU<-sprintf("%1.2f",0.2064792 *100)
PC2_SU
[1] "20.65"
#Prepare for Plotting
Color_SU.PCA_scores <- as.data.frame(Color_SU.PCA$scores[,c(1:2)])
Color_SU.PCA_scores$ID<-rownames(Color_SU.PCA_scores)
Color_SU.PCA_scores<-merge(Color_SU.PCA_scores, SampData)
#Plot PCA
Color_SU.PCA.plot<-ggplot(data = Color_SU.PCA_scores, aes(x = Comp.1, y = Comp.2)) +
geom_point(data = Color_SU.PCA_scores, aes(colour = Treatment), size = point.sz-1, alpha = 0.8) +
scale_colour_manual(values =HC.colors.o)+
theme_classic()+
scale_x_continuous(limits = c(-6, 12))+
scale_y_continuous(limits = c(-9, 9))+
labs(x=paste0('PC 1 (',PC1_SU,"%)"), y=paste0('PC 2 (',PC2_SU,"%)"))+
theme(axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="top");Color_SU.PCA.plot
Samples align along PC1 according to Treatment (Heated vs Control). Coordinates along PC1 will be extracted as the Color Score. Coordinates will multiplied by -1 for intuitive interpretation (Control > Heated) then made positive by adding 20
#Subset Winter Set
Color_WI<-subset(Color, Season=="Winter")
#Create matrix of standardized colors
Color_WI.mat <- as.matrix(cbind(Color_WI$Red.Norm.Coral,Color_WI$Green.Norm.Coral,Color_WI$Blue.Norm.Coral))
#Set row names to sample ID
rownames(Color_WI.mat) <- Color_WI$ID
#Create a Distance Matrix for PCA
Color_WI.dist <- vegdist(Color_WI.mat, method="euclidean", na.rm=TRUE)
#Run Principal Components Analysis
Color_WI.PCA <- princomp(Color_WI.dist)
#Initial plot
fviz_pca_ind(Color_WI.PCA)
#Check Variance Explained by Components
summary(Color_WI.PCA)
Importance of components:
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
Standard deviation 1.2309346 0.7018463 0.15366039 0.120048435 0.093361902
Proportion of Variance 0.7338452 0.2385715 0.01143558 0.006979873 0.004221569
Cumulative Proportion 0.7338452 0.9724167 0.98385224 0.990832109 0.995053678
Comp.6 Comp.7 Comp.8 Comp.9
Standard deviation 0.053096900 0.038343465 0.0330487379 0.0287023366
Proportion of Variance 0.001365441 0.000712061 0.0005289861 0.0003989964
Cumulative Proportion 0.996419119 0.997131180 0.9976601659 0.9980591623
Comp.10 Comp.11 Comp.12 Comp.13
Standard deviation 0.0248875165 0.0238476306 0.0214482809 0.0184060325
Proportion of Variance 0.0002999837 0.0002754387 0.0002228022 0.0001640797
Cumulative Proportion 0.9983591460 0.9986345847 0.9988573869 0.9990214666
Comp.14 Comp.15 Comp.16 Comp.17
Standard deviation 0.0175464260 1.383209e-02 1.305697e-02 1.233098e-02
Proportion of Variance 0.0001491117 9.266378e-05 8.256949e-05 7.364273e-05
Cumulative Proportion 0.9991705783 9.992632e-01 9.993458e-01 9.994195e-01
Comp.18 Comp.19 Comp.20 Comp.21
Standard deviation 1.226782e-02 1.080529e-02 1.019493e-02 9.936816e-03
Proportion of Variance 7.289026e-05 5.654668e-05 5.033883e-05 4.782214e-05
Cumulative Proportion 9.994923e-01 9.995489e-01 9.995992e-01 9.996471e-01
Comp.22 Comp.23 Comp.24 Comp.25
Standard deviation 0.0088345025 8.167480e-03 7.928379e-03 7.367121e-03
Proportion of Variance 0.0000378006 3.230805e-05 3.044411e-05 2.628634e-05
Cumulative Proportion 0.9996848528 9.997172e-01 9.997476e-01 9.997739e-01
Comp.26 Comp.27 Comp.28 Comp.29
Standard deviation 7.331757e-03 6.472753e-03 6.268150e-03 6.116798e-03
Proportion of Variance 2.603458e-05 2.029143e-05 1.902888e-05 1.812102e-05
Cumulative Proportion 9.997999e-01 9.998202e-01 9.998392e-01 9.998574e-01
Comp.30 Comp.31 Comp.32 Comp.33
Standard deviation 5.943301e-03 5.841620e-03 5.272834e-03 5.248384e-03
Proportion of Variance 1.710763e-05 1.652727e-05 1.346551e-05 1.334092e-05
Cumulative Proportion 9.998745e-01 9.998910e-01 9.999045e-01 9.999178e-01
Comp.34 Comp.35 Comp.36 Comp.37
Standard deviation 4.566595e-03 4.468233e-03 4.438093e-03 4.176434e-03
Proportion of Variance 1.009995e-05 9.669546e-06 9.539537e-06 8.447840e-06
Cumulative Proportion 9.999279e-01 9.999376e-01 9.999471e-01 9.999556e-01
Comp.38 Comp.39 Comp.40 Comp.41
Standard deviation 3.945923e-03 3.913443e-03 3.737298e-03 3.495544e-03
Proportion of Variance 7.541048e-06 7.417413e-06 6.764723e-06 5.917851e-06
Cumulative Proportion 9.999631e-01 9.999705e-01 9.999773e-01 9.999832e-01
Comp.42 Comp.43 Comp.44 Comp.45
Standard deviation 3.278510e-03 3.203026e-03 2.732893e-03 1.845243e-03
Proportion of Variance 5.205802e-06 4.968844e-06 3.617262e-06 1.649080e-06
Cumulative Proportion 9.999884e-01 9.999934e-01 9.999970e-01 9.999986e-01
Comp.46 Comp.47 Comp.48
Standard deviation 1.461483e-03 8.103806e-04 0
Proportion of Variance 1.034480e-06 3.180626e-07 0
Cumulative Proportion 9.999997e-01 1.000000e+00 1
#Visualize the importance of each principal component
fviz_eig(Color_WI.PCA, addlabels = TRUE)
PC1 Explains 73.4% of the variance in the color data.
#% Variance PCA 1
PC1_WI<-sprintf("%1.2f",0.7338452 *100)
PC1_WI
[1] "73.38"
#% Variance PCA 2
PC2_WI<-sprintf("%1.2f",0.2385715 *100)
PC2_WI
[1] "23.86"
#Prepare for Plotting
Color_WI.PCA_scores <- as.data.frame(Color_WI.PCA$scores[,c(1:2)])
Color_WI.PCA_scores$ID<-rownames(Color_WI.PCA_scores)
Color_WI.PCA_scores<-merge(Color_WI.PCA_scores, SampData)
#Plot PCA
Color_WI.PCA.plot<-ggplot(data = Color_WI.PCA_scores, aes(x = Comp.1, y = Comp.2)) +
geom_point(data = Color_WI.PCA_scores, aes(colour = Treatment), size = point.sz-1, alpha = 0.8) +
scale_colour_manual(values =HC.colors.o)+
theme_classic()+
scale_x_continuous(limits = c(-6, 12))+
scale_y_continuous(limits = c(-9, 9))+
labs(x=paste0('PC 1 (',PC1_WI,"%)"), y=paste0('PC 2 (',PC2_WI,"%)"))+
theme(axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="top");Color_WI.PCA.plot
Samples align along PC1 according to Treatment (Heated vs Control). Coordinates along PC1 will be extracted as the Color Score. *Note: These coordinates should not be multiplied by -1 for intuitive interpretation (Control > Heated), but will still be made positive by adding 20
#Subset Spring Set
Color_SP<-subset(Color, Season=="Spring")
#Create matrix of standardized colors
Color_SP.mat <- as.matrix(cbind(Color_SP$Red.Norm.Coral,Color_SP$Green.Norm.Coral,Color_SP$Blue.Norm.Coral))
#Set row names to sample ID
rownames(Color_SP.mat) <- Color_SP$ID
#Create a Distance Matrix for PCA
Color_SP.dist <- vegdist(Color_SP.mat, method="euclidean", na.rm=TRUE)
#Run Principal Components Analysis
Color_SP.PCA <- princomp(Color_SP.dist)
#Initial plot
fviz_pca_ind(Color_SP.PCA)
#Check Variance Explained by Components
summary(Color_SP.PCA)
Importance of components:
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5
Standard deviation 0.8098439 0.4333088 0.09461894 0.06515443 0.058919229
Proportion of Variance 0.7569193 0.2166915 0.01033245 0.00489931 0.004006463
Cumulative Proportion 0.7569193 0.9736108 0.98394326 0.98884257 0.992849031
Comp.6 Comp.7 Comp.8 Comp.9 Comp.10
Standard deviation 0.044077309 0.0308445 0.0246012130 0.0242826222 0.0184116841
Proportion of Variance 0.002242214 0.0010980 0.0006984897 0.0006805157 0.0003912317
Cumulative Proportion 0.995091245 0.9961892 0.9968877348 0.9975682505 0.9979594822
Comp.11 Comp.12 Comp.13 Comp.14
Standard deviation 0.0161493736 0.0142114594 0.0137494920 0.011334062
Proportion of Variance 0.0003009944 0.0002330904 0.0002181827 0.000148258
Cumulative Proportion 0.9982604765 0.9984935669 0.9987117496 0.998860008
Comp.15 Comp.16 Comp.17 Comp.18
Standard deviation 0.0109649690 0.0094676980 9.159072e-03 8.495106e-03
Proportion of Variance 0.0001387592 0.0001034513 9.681663e-05 8.328842e-05
Cumulative Proportion 0.9989987668 0.9991022181 9.991990e-01 9.992823e-01
Comp.19 Comp.20 Comp.21 Comp.22
Standard deviation 7.763228e-03 7.701411e-03 7.064981e-03 6.725859e-03
Proportion of Variance 6.955553e-05 6.845222e-05 5.760617e-05 5.220866e-05
Cumulative Proportion 9.993519e-01 9.994203e-01 9.994779e-01 9.995301e-01
Comp.23 Comp.24 Comp.25 Comp.26
Standard deviation 6.558260e-03 6.153358e-03 5.552261e-03 5.168112e-03
Proportion of Variance 4.963914e-05 4.369899e-05 3.557843e-05 3.082555e-05
Cumulative Proportion 9.995798e-01 9.996235e-01 9.996591e-01 9.996899e-01
Comp.27 Comp.28 Comp.29 Comp.30
Standard deviation 5.026726e-03 4.861890e-03 4.644134e-03 4.538340e-03
Proportion of Variance 2.916201e-05 2.728081e-05 2.489181e-05 2.377065e-05
Cumulative Proportion 9.997190e-01 9.997463e-01 9.997712e-01 9.997950e-01
Comp.31 Comp.32 Comp.33 Comp.34
Standard deviation 4.270442e-03 4.189387e-03 4.088007e-03 0.0039213027
Proportion of Variance 2.104712e-05 2.025574e-05 1.928725e-05 0.0000177463
Cumulative Proportion 9.998160e-01 9.998363e-01 9.998556e-01 0.9998733295
Comp.35 Comp.36 Comp.37 Comp.38
Standard deviation 3.808023e-03 3.674472e-03 0.003562953 3.532163e-03
Proportion of Variance 1.673579e-05 1.558249e-05 0.000014651 1.439887e-05
Cumulative Proportion 9.998901e-01 9.999056e-01 0.999920299 9.999347e-01
Comp.39 Comp.40 Comp.41 Comp.42
Standard deviation 0.0033427124 3.257387e-03 3.131059e-03 2.405568e-03
Proportion of Variance 0.0000128957 1.224576e-05 1.131435e-05 6.678552e-06
Cumulative Proportion 0.9999475933 9.999598e-01 9.999712e-01 9.999778e-01
Comp.43 Comp.44 Comp.45 Comp.46
Standard deviation 2.325405e-03 2.170286e-03 1.993345e-03 1.900185e-03
Proportion of Variance 6.240856e-06 5.436017e-06 4.585768e-06 4.167147e-06
Cumulative Proportion 9.999841e-01 9.999895e-01 9.999941e-01 9.999983e-01
Comp.47 Comp.48
Standard deviation 1.227238e-03 0
Proportion of Variance 1.738219e-06 0
Cumulative Proportion 1.000000e+00 1
#Visualize the importance of each principal component
fviz_eig(Color_SP.PCA, addlabels = TRUE)
PC1 Explains 75.7% of the variance in the color data.
#% Variance PCA 1
PC1_SP<-sprintf("%1.2f",0.7569193 *100)
PC1_SP
[1] "75.69"
#% Variance PCA 2
PC2_SP<-sprintf("%1.2f",0.2166915 *100)
PC2_SP
[1] "21.67"
#Prepare for Plotting
Color_SP.PCA_scores <- as.data.frame(Color_SP.PCA$scores[,c(1:2)])
Color_SP.PCA_scores$ID<-rownames(Color_SP.PCA_scores)
Color_SP.PCA_scores<-merge(Color_SP.PCA_scores, SampData)
#Plot PCA
Color_SP.PCA.plot<-ggplot(data = Color_SP.PCA_scores, aes(x = Comp.1, y = Comp.2)) +
geom_point(data = Color_SP.PCA_scores, aes(colour = Treatment), size = point.sz-1, alpha = 0.8) +
scale_colour_manual(values =HC.colors.o)+
theme_classic()+
scale_x_continuous(limits = c(-6, 12))+
scale_y_continuous(limits = c(-9, 9))+
labs(x=paste0('PC 1 (',PC1_SP,"%)"), y=paste0('PC 2 (',PC2_SP,"%)"))+
theme(axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="top");Color_SP.PCA.plot
Samples align along PC1 according to Treatment, but less separation between Heated vs Control. Coordinates along PC1 will be extracted as the Color Score. Coordinates will multiplied by -1 for intuitive interpretation (Control > Heated) then made positive by adding 20
##Merge with Color Data
names(ColorData.Seas)
[1] "ID" "Comp.1" "Comp.2" "RandN" "TimeP" "Site"
[7] "Genotype" "Treat" "Treatment" "Vol_ml" "Wax.I_g" "Wax.F_g"
[13] "Set" "Score_Seas" "Season"
names(ColorData)
[1] "ID" "RandN" "TimeP" "Site" "Genotype" "Treat"
[7] "Treatment" "Set" "Score_Full" "Score_TP" "Score_Set" "Score_Seas"
cor(ColorData[,c(9:12)])
Score_Full Score_TP Score_Set Score_Seas
Score_Full 1.0000000 0.8008984 0.8934140 0.8943347
Score_TP 0.8008984 1.0000000 0.8524334 0.8858928
Score_Set 0.8934140 0.8524334 1.0000000 0.9583848
Score_Seas 0.8943347 0.8858928 0.9583848 1.0000000
chart.Correlation(ColorData[,c(9:12)], histogram=TRUE, pch=19)
All calculations of Color score between the Full Dataset, Individual PCA’s by Timepoints, or either Analysis / Seasonal sets are all highly correlated with each other.
##Add an Analysis Set Variable
ColorData$AnSet<-"Initial"
ColorData$AnSet[which(ColorData$TimeP=="M4" | ColorData$TimeP== "M8")]<-"Seasonal"
ColorData$AnSet[which(ColorData$TimeP=="M12")]<-"Annual"
##Add Season Variable
ColorData$Season<-"Summer"
ColorData$Season[which(ColorData$TimeP=="M4")]<-"Winter"
ColorData$Season[which(ColorData$TimeP=="M8")]<-"Spring"
##Write out
write.csv(ColorData, "Outputs/ScoreData.csv", row.names=FALSE)